From: Michael Tremer Date: Thu, 30 Jan 2025 20:06:06 +0000 (+0000) Subject: repo: Have the function to return all packages as list create the list X-Git-Tag: 0.9.30~242 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee33be0803b0f3d461713143a4f265a671703f9f;p=pakfire.git repo: Have the function to return all packages as list create the list Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index 4c3c5d5b..e3c86ea5 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -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;