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 \
#include <pakfire/packagelist.h>
#include <pakfire/root.h>
#include <pakfire/repo.h>
-#include <pakfire/repolist.h>
#include "dump.h"
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;
#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 */
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;
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);
+++ /dev/null
-/*#############################################################################
-# #
-# 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;
-}
+++ /dev/null
-/*#############################################################################
-# #
-# 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 */
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;
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,
#include <pakfire/root.h>
#include <pakfire/key.h>
#include <pakfire/repo.h>
-#include <pakfire/repolist.h>
#include <pakfire/transaction.h>
#include <pakfire/util.h>
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;
}