]> git.ipfire.org Git - pakfire.git/commitdiff
repos: Implement subpriorities to prefer local packages when possible
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 20 Sep 2023 18:26:05 +0000 (18:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 20 Sep 2023 18:26:05 +0000 (18:26 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/repo.c

index adb77b0daa68fd2b6373a742a666f6c73b5a1a24..fe6db599953562742ab461e33df14bfe828e2c69 100644 (file)
@@ -107,6 +107,23 @@ int pakfire_repo_is_local(struct pakfire_repo* repo) {
        return pakfire_string_startswith(repo->appdata->baseurl, "file://");
 }
 
+/*
+       LIBSOLV knows a subpriority which is a good way to indicate that
+       packages from a local repository should be preferred without
+       preferring an older version of a package over a new one.
+
+       We set this automatically to reduce bandwidth usage.
+ */
+static void pakfire_repo_update_subpriority(struct pakfire_repo* repo) {
+       // Prefer local repositories
+       if (pakfire_repo_is_local(repo))
+               repo->repo->subpriority = 1;
+
+       // Otherwise reset
+       else
+               repo->repo->subpriority = 0;
+}
+
 int pakfire_repo_name_equals(struct pakfire_repo* repo, const char* name) {
        const char* n = pakfire_repo_get_name(repo);
        if (!n)
@@ -635,6 +652,9 @@ PAKFIRE_EXPORT int pakfire_repo_create(struct pakfire_repo** repo,
                goto ERROR;
        }
 
+       // Update the subpriority
+       pakfire_repo_update_subpriority(rep);
+
        // Setup/clear repository data
        r = pakfire_repo_clear(rep);
        if (r)
@@ -846,6 +866,9 @@ PAKFIRE_EXPORT int pakfire_repo_set_baseurl(struct pakfire_repo* repo, const cha
        if (!repo->appdata->baseurl)
                return 1;
 
+       // Update sub-priority
+       pakfire_repo_update_subpriority(repo);
+
        return 0;
 }