From: Michael Tremer Date: Sun, 29 Jun 2025 14:43:19 +0000 (+0000) Subject: repolist: Drop the entire thing X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1c28fdf5bd1f067044ef46e72b023b0842e1b04d;p=pakfire.git repolist: Drop the entire thing We have a callback to walk through all repositories which works well enough for us here. Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index b55aeb60..94678914 100644 --- a/Makefile.am +++ b/Makefile.am @@ -292,8 +292,6 @@ libpakfire_la_SOURCES = \ src/pakfire/pwd.h \ src/pakfire/repo.c \ src/pakfire/repo.h \ - src/pakfire/repolist.c \ - src/pakfire/repolist.h \ src/pakfire/root.c \ src/pakfire/root.h \ src/pakfire/scriptlet.c \ diff --git a/src/cli/lib/dump.c b/src/cli/lib/dump.c index 84abe55e..136c73d9 100644 --- a/src/cli/lib/dump.c +++ b/src/cli/lib/dump.c @@ -29,7 +29,6 @@ #include #include #include -#include #include "dump.h" @@ -65,39 +64,6 @@ int cli_dump_packagelist(pakfire_packagelist* list, int flags) { return pakfire_packagelist_walk(list, __cli_dump_package, &flags, 0); } -int cli_dump_repolist(pakfire_repolist* list, int flags) { - pakfire_repo* repo = NULL; - int r; - - if (!list) - return 0; - - // Print the header - r = printf(" %-20s %8s %12s %12s \n", "Repository", "Enabled", "Priority", "Packages"); - if (r < 0) - goto ERROR; - - size_t length = pakfire_repolist_size(list); - - for (unsigned int i = 0; i < length; i++) { - repo = pakfire_repolist_get(list, i); - if (!repo) - break; - - r = printf(" %-20s %8s %12d %12d \n", - pakfire_repo_get_name(repo), - pakfire_repo_get_enabled(repo) ? "Yes" : "No", - pakfire_repo_get_priority(repo), - pakfire_repo_count(repo)); - pakfire_repo_unref(repo); - if (r < 0) - goto ERROR; - } - -ERROR: - return r; -} - int cli_dump_json(json_object* object) { int r; diff --git a/src/cli/lib/dump.h b/src/cli/lib/dump.h index 5c989d62..87c1a034 100644 --- a/src/cli/lib/dump.h +++ b/src/cli/lib/dump.h @@ -26,13 +26,10 @@ #include #include #include -#include int cli_dump_package(pakfire_package* package, int flags); int cli_dump_packagelist(pakfire_packagelist* list, int flags); -int cli_dump_repolist(pakfire_repolist* list, int flags); - int cli_dump_json(json_object* object); #endif /* PAKFIRE_CLI_DUMP_H */ diff --git a/src/cli/lib/repolist.c b/src/cli/lib/repolist.c index a29c8183..66c66b34 100644 --- a/src/cli/lib/repolist.c +++ b/src/cli/lib/repolist.c @@ -30,9 +30,18 @@ static const char* doc = "List all available repositories"; +#define REPO_FORMAT " %-20s %8s %12s %12s \n" + +static int cli_dump_repo(pakfire_root* root, pakfire_repo* repo, void* data) { + return printf(" %-20s %8s %12d %12d \n", + pakfire_repo_get_name(repo), + pakfire_repo_get_enabled(repo) ? "Yes" : "No", + pakfire_repo_get_priority(repo), + pakfire_repo_count(repo)); +} + int cli_repolist(void* data, int argc, char* argv[]) { struct cli_global_args* global_args = data; - pakfire_repolist* list = NULL; pakfire_root* root = NULL; int r; @@ -46,19 +55,15 @@ int cli_repolist(void* data, int argc, char* argv[]) { if (r) goto ERROR; - // Fetch all repositories - list = pakfire_root_get_repos(root); - if (!list) { - r = -errno; + // Print the header + r = printf(" %-20s %8s %12s %12s \n", "Repository", "Enabled", "Priority", "Packages"); + if (r < 0) goto ERROR; - } - // Dump the repolist - r = cli_dump_repolist(list, 0); + // Show all repositories + r = pakfire_root_repo_walk(root, cli_dump_repo, NULL); ERROR: - if (list) - pakfire_repolist_unref(list); if (root) pakfire_root_unref(root); diff --git a/src/pakfire/repolist.c b/src/pakfire/repolist.c deleted file mode 100644 index 9013ea91..00000000 --- a/src/pakfire/repolist.c +++ /dev/null @@ -1,123 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2021 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#include -#include - -#include -#include - -struct pakfire_repolist { - int nrefs; - - pakfire_repo** elements; - size_t elements_size; - - size_t size; -}; - -static int pakfire_repolist_grow(pakfire_repolist* list, size_t size) { - pakfire_repo** elements = reallocarray(list->elements, - list->elements_size + size, sizeof(*list->elements)); - if (!elements) - return -errno; - - list->elements = elements; - list->elements_size += size; - - return 0; -} - -int pakfire_repolist_create(pakfire_repolist** list) { - pakfire_repolist* l = calloc(1, sizeof(*l)); - if (!l) - return ENOMEM; - - l->nrefs = 1; - - *list = l; - return 0; -} - -pakfire_repolist* pakfire_repolist_ref( - pakfire_repolist* list) { - list->nrefs++; - - return list; -} - -static void pakfire_repolist_free(pakfire_repolist* list) { - pakfire_repolist_clear(list); - free(list); -} - -pakfire_repolist* pakfire_repolist_unref( - pakfire_repolist* list) { - if (--list->nrefs > 0) - return list; - - pakfire_repolist_free(list); - return NULL; -} - -void pakfire_repolist_clear(pakfire_repolist* list) { - if (!list->elements) - return; - - for (unsigned int i = 0; i < list->size; i++) - pakfire_repo_unref(list->elements[i]); - - free(list->elements); - list->elements = NULL; - list->elements_size = 0; - - list->size = 0; -} - -size_t pakfire_repolist_size(pakfire_repolist* list) { - return list->size; -} - -int pakfire_repolist_empty(pakfire_repolist* list) { - return list->size == 0; -} - -pakfire_repo* pakfire_repolist_get(pakfire_repolist* list, size_t index) { - if (index >= list->size) - return NULL; - - return pakfire_repo_ref(list->elements[index]); -} - -int pakfire_repolist_append(pakfire_repolist* list, pakfire_repo* repo) { - if (!repo) - return EINVAL; - - // Check if we have any space left - if (list->size >= list->elements_size) { - int r = pakfire_repolist_grow(list, 64); - if (r) - return r; - } - - list->elements[list->size++] = pakfire_repo_ref(repo); - - return 0; -} diff --git a/src/pakfire/repolist.h b/src/pakfire/repolist.h deleted file mode 100644 index f0af1332..00000000 --- a/src/pakfire/repolist.h +++ /dev/null @@ -1,41 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2021 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#ifndef PAKFIRE_REPOLIST_H -#define PAKFIRE_REPOLIST_H - -#include - -typedef struct pakfire_repolist pakfire_repolist; - -int pakfire_repolist_create(pakfire_repolist** list); - -pakfire_repolist* pakfire_repolist_ref(pakfire_repolist* list); -pakfire_repolist* pakfire_repolist_unref(pakfire_repolist* list); - -void pakfire_repolist_clear(pakfire_repolist* list); - -size_t pakfire_repolist_size(pakfire_repolist* list); -int pakfire_repolist_empty(pakfire_repolist* list); - -pakfire_repo* pakfire_repolist_get(pakfire_repolist* list, size_t index); -int pakfire_repolist_append(pakfire_repolist* list, pakfire_repo* repo); - -#endif /* PAKFIRE_REPOLIST_H */ diff --git a/src/pakfire/root.c b/src/pakfire/root.c index 82fac88e..9fc7b0e0 100644 --- a/src/pakfire/root.c +++ b/src/pakfire/root.c @@ -1358,45 +1358,6 @@ void pakfire_root_pool_internalize(pakfire_root* self) { self->internal_flags |= PAKFIRE_ROOT_POOL_READY; } -pakfire_repolist* pakfire_root_get_repos(pakfire_root* self) { - pakfire_repo* repo = NULL; - pakfire_repolist* list; - - int r = pakfire_repolist_create(&list); - if (r) - return NULL; - - Pool* pool = pakfire_root_get_solv_pool(self); - Repo* solv_repo; - int i; - - FOR_REPOS(i, solv_repo) { - // Skip the dummy repository - if (strcmp(solv_repo->name, PAKFIRE_REPO_DUMMY) == 0) - continue; - - // Create repository - r = pakfire_repo_open(&repo, self->ctx, self, solv_repo); - if (r < 0) - goto ERROR; - - // Append it to the list - r = pakfire_repolist_append(list, repo); - if (r) { - pakfire_repo_unref(repo); - goto ERROR; - } - - pakfire_repo_unref(repo); - } - - return list; - -ERROR: - pakfire_repolist_unref(list); - return NULL; -} - pakfire_repo* pakfire_root_get_repo(pakfire_root* self, const char* name) { pakfire_repo* repo = NULL; Repo* solv_repo = NULL; diff --git a/src/pakfire/root.h b/src/pakfire/root.h index cfe9c9e1..725bb908 100644 --- a/src/pakfire/root.h +++ b/src/pakfire/root.h @@ -69,7 +69,6 @@ const char* pakfire_root_get_arch(pakfire_root* pakfire); int pakfire_root_version_compare(pakfire_root* pakfire, const char* evr1, const char* evr2); -pakfire_repolist* pakfire_root_get_repos(pakfire_root* pakfire); pakfire_repo* pakfire_root_get_repo(pakfire_root* pakfire, const char* name); int pakfire_root_whatprovides(pakfire_root* pakfire, const char* what, int flags, diff --git a/src/python/root.c b/src/python/root.c index 7074bc1a..22f79e3b 100644 --- a/src/python/root.c +++ b/src/python/root.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include @@ -387,32 +386,38 @@ static PyObject* Root_dist(RootObject* self, PyObject* args) { return ret; } -static PyObject* Root_get_repos(RootObject* self) { - pakfire_repolist* repos = pakfire_root_get_repos(self->root); - if (!repos) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } +static int add_repo(pakfire_root* root, pakfire_repo* repo, void* data) { + PyObject* list = data; + PyObject* object = NULL; + int r; - const size_t l = pakfire_repolist_size(repos); + // Create a new Repo object + object = new_repo(&RepoType, repo); + if (!object) + return -1; - PyObject* list = PyList_New(l); - if (!list) - goto ERROR; + // Append it to the list + r = PyList_Append(list, object); + Py_DECREF(object); - for (unsigned int i = 0; i < l; i++) { - pakfire_repo* repo = pakfire_repolist_get(repos, i); - if (!repo) - continue; + return r; +} - PyObject* obj = new_repo(&RepoType, repo); - PyList_SET_ITEM(list, i, obj); +static PyObject* Root_get_repos(RootObject* self) { + PyObject* list = NULL; + int r; - pakfire_repo_unref(repo); - } + // Create a new list + list = PyList_New(0); + if (!list) + return NULL; -ERROR: - pakfire_repolist_unref(repos); + // Populate the list + r = pakfire_root_repo_walk(self->root, add_repo, list); + if (r < 0) { + Py_DECREF(list); + return NULL; + } return list; }