]> git.ipfire.org Git - pakfire.git/commitdiff
repolist: Drop the entire thing
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 14:43:19 +0000 (14:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 14:43:19 +0000 (14:43 +0000)
We have a callback to walk through all repositories which works well
enough for us here.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/cli/lib/dump.c
src/cli/lib/dump.h
src/cli/lib/repolist.c
src/pakfire/repolist.c [deleted file]
src/pakfire/repolist.h [deleted file]
src/pakfire/root.c
src/pakfire/root.h
src/python/root.c

index b55aeb60bc1e51e8d63b3b56f9d470eb7f71abd3..94678914f4049c8aec5f69dff1c5e55fc183fc2c 100644 (file)
@@ -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 \
index 84abe55e9a6e6654bb62a6d759b919aa89b18180..136c73d90ef7bc6f30356b63d353a3435414b879 100644 (file)
@@ -29,7 +29,6 @@
 #include <pakfire/packagelist.h>
 #include <pakfire/root.h>
 #include <pakfire/repo.h>
-#include <pakfire/repolist.h>
 
 #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;
 
index 5c989d62ba6749681237485f3224aafa27252a3b..87c1a0349a008f3c563c43188f5650e0396ff482 100644 (file)
 #include <pakfire/package.h>
 #include <pakfire/packagelist.h>
 #include <pakfire/root.h>
-#include <pakfire/repolist.h>
 
 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 */
index a29c81834fb46d2f416305289a4010ee1b00dda0..66c66b34e8da1e92763e1f8fe10683402e4849a0 100644 (file)
 
 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 (file)
index 9013ea9..0000000
+++ /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 <http://www.gnu.org/licenses/>.       #
-#                                                                             #
-#############################################################################*/
-
-#include <errno.h>
-#include <stdlib.h>
-
-#include <pakfire/repo.h>
-#include <pakfire/repolist.h>
-
-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 (file)
index f0af133..0000000
+++ /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 <http://www.gnu.org/licenses/>.       #
-#                                                                             #
-#############################################################################*/
-
-#ifndef PAKFIRE_REPOLIST_H
-#define PAKFIRE_REPOLIST_H
-
-#include <pakfire/repo.h>
-
-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 */
index 82fac88ecabd0ff61b6473b1f4223e969b0e14c7..9fc7b0e0cce027e0f18e881c4798b5147b11764f 100644 (file)
@@ -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;
index cfe9c9e159d9cb7094a229d073d4d1728eae21cc..725bb9088e6f03bc00ed4a9c1d8a00402e97fd2c 100644 (file)
@@ -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,
index 7074bc1a75abcfcfc3041aa7a3669d1dc74c8e68..22f79e3b33a427742f2d7ca121fce813cc8d2e3d 100644 (file)
@@ -36,7 +36,6 @@
 #include <pakfire/root.h>
 #include <pakfire/key.h>
 #include <pakfire/repo.h>
-#include <pakfire/repolist.h>
 #include <pakfire/transaction.h>
 #include <pakfire/util.h>
 
@@ -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;
 }