]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Have the function to return all packages as list create the list
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 20:06:06 +0000 (20:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 20:06:06 +0000 (20:06 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/repo.c

index 4c3c5d5bf99e930af9f385424b223384dbdb8e74..e3c86ea5956587d337c01af237bf40b228384a10 100644 (file)
@@ -1014,6 +1014,50 @@ int pakfire_repo_count(struct pakfire_repo* repo) {
        return cnt;
 }
 
+static int pakfire_repo_to_packagelist(
+               struct pakfire_repo* self, struct pakfire_packagelist** list) {
+       struct pakfire_packagelist* l = NULL;
+       struct pakfire_package* pkg = NULL;
+       Solvable* s = NULL;
+       Id id;
+       int i;
+       int r;
+
+       // Create a new packagelist
+       r = pakfire_packagelist_create(&l, self->ctx);
+       if (r < 0)
+               goto ERROR;
+
+       FOR_REPO_SOLVABLES(self->repo, i, s) {
+               // Convert the solvable into an ID
+               id = pool_solvable2id(self->repo->pool, s);
+
+               // Create a new package
+               r = pakfire_package_create_from_solvable(&pkg, self->pakfire, id);
+               if (r < 0)
+                       goto ERROR;
+
+               // Add the package to the list
+               r = pakfire_packagelist_add(l, pkg);
+               if (r < 0)
+                       goto ERROR;
+
+               pakfire_package_unref(pkg);
+               pkg = NULL;
+       }
+
+       // Return the list
+       *list = pakfire_packagelist_ref(l);
+
+ERROR:
+       if (pkg)
+               pakfire_package_unref(pkg);
+       if (l)
+               pakfire_packagelist_unref(l);
+
+       return r;
+}
+
 void pakfire_repo_has_changed(struct pakfire_repo* repo) {
        repo->appdata->ready = 0;
 
@@ -2153,45 +2197,13 @@ ERROR:
        return r;
 }
 
-static int pakfire_repo_to_packagelist(struct pakfire_repo* repo,
-               struct pakfire_packagelist* list) {
-       struct pakfire_package* pkg = NULL;
-       Solvable* s = NULL;
-       Id id;
-       int i;
-       int r;
-
-       FOR_REPO_SOLVABLES(repo->repo, i, s) {
-               // Convert the solvable into an ID
-               id = pool_solvable2id(repo->repo->pool, s);
-
-               // Create a new package
-               r = pakfire_package_create_from_solvable(&pkg, repo->pakfire, id);
-               if (r < 0)
-                       return r;
-
-               // Add the package to the list
-               r = pakfire_packagelist_add(list, pkg);
-               pakfire_package_unref(pkg);
-               if (r < 0)
-                       return r;
-       }
-
-       return 0;
-}
-
 int pakfire_repo_walk_packages(struct pakfire_repo* self,
                int (*callback)(struct pakfire_ctx* ctx, struct pakfire_package* pkg, void* data), void* data, int flags) {
        struct pakfire_packagelist* list = NULL;
        int r;
 
-       // Create a new packagelist
-       r = pakfire_packagelist_create(&list, self->ctx);
-       if (r < 0)
-               goto ERROR;
-
        // Import all packages
-       r = pakfire_repo_to_packagelist(self, list);
+       r = pakfire_repo_to_packagelist(self, &list);
        if (r < 0)
                goto ERROR;
 
@@ -2250,13 +2262,8 @@ int pakfire_repo_walk_archives(struct pakfire_repo* self,
        if (!pakfire_repo_is_local(self))
                return -ENOTSUP;
 
-       // Create a new packagelist
-       r = pakfire_packagelist_create(&list, self->ctx);
-       if (r < 0)
-               goto ERROR;
-
        // Import all packages
-       r = pakfire_repo_to_packagelist(self, list);
+       r = pakfire_repo_to_packagelist(self, &list);
        if (r < 0)
                goto ERROR;