]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Change pakfire_repo_create to return int
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 19 Aug 2021 16:14:03 +0000 (16:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 19 Aug 2021 16:14:03 +0000 (16:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/repo.c
src/libpakfire/include/pakfire/repo.h
src/libpakfire/pakfire.c
src/libpakfire/repo.c
src/libpakfire/request.c

index 764d104c6a2935d8ea25ea523cade32badd294c0..4559a5a9d18136b40b18450ca42f403f858d3912 100644 (file)
@@ -62,8 +62,8 @@ static int Repo_init(RepoObject* self, PyObject* args, PyObject* kwds) {
                return -1;
 
        // Create a new repository
-       self->repo = pakfire_repo_create(pakfire->pakfire, name);
-       if (!self->repo) {
+       int r = pakfire_repo_create(&self->repo, pakfire->pakfire, name);
+       if (r) {
                PyErr_SetFromErrno(PyExc_OSError);
                return -1;
        }
index d9b31aab18cfeb4cf94b251701d67bc96dcc1b57..c9edbe6fe3be36b03159cfb9bda25dbce52a3da3 100644 (file)
@@ -30,7 +30,7 @@ struct pakfire_repo;
 #include <pakfire/archive.h>
 #include <pakfire/package.h>
 
-struct pakfire_repo* pakfire_repo_create(struct pakfire* pakfire, const char* name);
+int pakfire_repo_create(struct pakfire_repo** repo, struct pakfire* pakfire, const char* name);
 
 struct pakfire_repo* pakfire_repo_ref(struct pakfire_repo* repo);
 struct pakfire_repo* pakfire_repo_unref(struct pakfire_repo* repo);
index ba4ece6aaeb88644dee4f561cf7278dfdc802d60..a50a7d808789352492be5638b381d3296a4982dc 100644 (file)
@@ -404,8 +404,8 @@ static Id pakfire_namespace_callback(Pool* pool, void* data, Id ns, Id id) {
 
 static int pakfire_populate_pool(struct pakfire* pakfire) {
        struct pakfire_db* db;
-       struct pakfire_repo* repo = NULL;
        struct pakfire_repo* dummy = NULL;
+       struct pakfire_repo* system = NULL;
        int r;
 
        // Initialize the pool
@@ -435,33 +435,33 @@ static int pakfire_populate_pool(struct pakfire* pakfire) {
                goto ERROR;
 
        // Create a dummy repository
-       dummy = pakfire_repo_create(pakfire, "@dummy");
-       if (!dummy)
+       r = pakfire_repo_create(&dummy, pakfire, "@dummy");
+       if (r)
                goto ERROR;
 
        // Disable the repository
        pakfire_repo_set_enabled(dummy, 0);
 
        // Create the system repository
-       repo = pakfire_repo_create(pakfire, "@system");
-       if (!repo)
+       r = pakfire_repo_create(&system, pakfire, "@system");
+       if (r)
                goto ERROR;
 
        // Set this repository as the installed one
-       pool_set_installed(pool, pakfire_repo_get_repo(repo));
+       pool_set_installed(pool, pakfire_repo_get_repo(system));
 
        // Load database content
-       r = pakfire_db_load(db, repo);
+       r = pakfire_db_load(db, system);
        if (r)
                goto ERROR;
 
 ERROR:
        if (db)
                pakfire_db_unref(db);
-       if (repo)
-               pakfire_repo_unref(repo);
        if (dummy)
                pakfire_repo_unref(dummy);
+       if (system)
+               pakfire_repo_unref(system);
 
        return r;
 }
index 44e0cef7a22cc2fc3703163d4edd039c6884fd5e..68e984fd60370c39dae86340b5b71267684c25b5 100644 (file)
@@ -153,6 +153,7 @@ int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config)
        if (!sections)
                return 0;
 
+       struct pakfire_repo* repo = NULL;
        int r = 0;
 
        // Walk through all sections
@@ -168,10 +169,9 @@ int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config)
                DEBUG(pakfire, "Creating repository %s\n", name);
 
                // Create a new repository
-               struct pakfire_repo* repo = pakfire_repo_create(pakfire, name);
-               if (!repo) {
+               r = pakfire_repo_create(&repo, pakfire, name);
+               if (r) {
                        ERROR(pakfire, "Could not create repository '%s': %m\n", name);
-                       r = 1;
                        goto ERROR;
                }
 
@@ -426,73 +426,76 @@ void pakfire_repo_free_all(struct pakfire* pakfire) {
        }
 }
 
-PAKFIRE_EXPORT struct pakfire_repo* pakfire_repo_create(struct pakfire* pakfire, const char* name) {
-       struct pakfire_repo* repo;
-       int r;
+PAKFIRE_EXPORT int pakfire_repo_create(struct pakfire_repo** repo,
+               struct pakfire* pakfire, const char* name) {
+       int r = 1;
 
        // Return existing repositories with the same name
-       repo = pakfire_get_repo(pakfire, name);
-       if (repo)
-               return repo;
+       struct pakfire_repo* rep = pakfire_get_repo(pakfire, name);
+       if (rep) {
+               *repo = rep;
+               return 0;
+       }
 
        // Create a new one
-       repo = calloc(1, sizeof(*repo));
-       if (!repo)
-               return NULL;
+       rep = calloc(1, sizeof(*rep));
+       if (!rep)
+               return 1;
 
-       repo->pakfire = pakfire_ref(pakfire);
-       repo->nrefs = 1;
+       rep->pakfire = pakfire_ref(pakfire);
+       rep->nrefs = 1;
 
        Pool* pool = pakfire_get_solv_pool(pakfire);
 
        // Allocate a libsolv repository
-       repo->repo = repo_create(pool, name);
-       if (!repo->repo) {
-               ERROR(repo->pakfire, "Could not allocate repo: %m\n");
+       rep->repo = repo_create(pool, name);
+       if (!rep->repo) {
+               ERROR(rep->pakfire, "Could not allocate repo: %m\n");
                goto ERROR;
        }
 
        // Allocate repository appdata
-       repo->appdata = repo->repo->appdata = calloc(1, sizeof(*repo->appdata));
-       if (!repo->appdata) {
-               ERROR(repo->pakfire, "Could not allocate repo appdata\n");
+       rep->appdata = rep->repo->appdata = calloc(1, sizeof(*rep->appdata));
+       if (!rep->appdata) {
+               ERROR(rep->pakfire, "Could not allocate repo appdata\n");
                goto ERROR;
        }
 
        // Setup/clear repository data
-       r = pakfire_repo_clear(repo);
+       r = pakfire_repo_clear(rep);
        if (r)
                goto ERROR;
 
        // Skip remaining initialization for "internal" repositories
-       if (pakfire_repo_is_internal(repo))
-               return repo;
+       if (pakfire_repo_is_internal(rep))
+               return 0;
 
        // Make path to mirrorlist
-       r = pakfire_make_cache_path(pakfire, repo->appdata->mirrorlist,
-               "repodata/%s/mirrorlist", pakfire_repo_get_name(repo));
+       r = pakfire_make_cache_path(pakfire, rep->appdata->mirrorlist,
+               "repodata/%s/mirrorlist", pakfire_repo_get_name(rep));
        if (r < 0)
                goto ERROR;
 
        // Make path for metadata
-       r = pakfire_make_cache_path(pakfire, repo->appdata->metadata,
-               "repodata/%s/repomd.json", pakfire_repo_get_name(repo));
+       r = pakfire_make_cache_path(pakfire, rep->appdata->metadata,
+               "repodata/%s/repomd.json", pakfire_repo_get_name(rep));
        if (r < 0)
                goto ERROR;
 
        // Try loading metadata
-       r = pakfire_repo_read_metadata(repo, repo->appdata->metadata, 0);
+       r = pakfire_repo_read_metadata(rep, rep->appdata->metadata, 0);
        if (r) {
-               ERROR(repo->pakfire, "Could not initialize repository metadata: %m\n");
+               ERROR(rep->pakfire, "Could not initialize repository metadata: %m\n");
                goto ERROR;
        }
 
-       return repo;
+       *repo = rep;
+       return 0;
 
 ERROR:
-       pakfire_repo_free(repo, 1);
+       pakfire_repo_free(rep, 1);
 
-       return NULL;
+       return r;
 }
 
 struct pakfire_repo* pakfire_repo_create_from_repo(struct pakfire* pakfire, Repo* r) {
index bb8bdc7c435b18b230d11b157b4db28ecc2c5844..b50a802ae4e714f8b3bbf8c8a6a6922f662d38cd 100644 (file)
@@ -389,16 +389,19 @@ static int pakfire_request_add_job(struct pakfire_request* request, int action,
 
 static int pakfire_request_add_archive(struct pakfire_request* request, int action,
                struct pakfire_archive* archive, int extra_flags) {
-       struct pakfire_repo* repo = pakfire_repo_create(request->pakfire, "@commandline");
-       if (!repo)
-               return 1;
+       struct pakfire_repo* repo = NULL;
+       int r;
+
+       r = pakfire_repo_create(&repo, request->pakfire, "@commandline");
+       if (r)
+               return r;
 
        // Add it to the repository
        struct pakfire_package* pkg = pakfire_repo_add_archive(repo, archive);
        if (!pkg)
                goto ERROR;
 
-       int r = pakfire_request_add_package(request, action, pkg, extra_flags);
+       r = pakfire_request_add_package(request, action, pkg, extra_flags);
        if (r)
                goto ERROR;