From: Michael Tremer Date: Thu, 19 Aug 2021 16:14:03 +0000 (+0000) Subject: repo: Change pakfire_repo_create to return int X-Git-Tag: 0.9.28~993 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14fe6b074b529fa9884ae6ef95d1d5dfe853c0c8;p=pakfire.git repo: Change pakfire_repo_create to return int Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/repo.c b/src/_pakfire/repo.c index 764d104c6..4559a5a9d 100644 --- a/src/_pakfire/repo.c +++ b/src/_pakfire/repo.c @@ -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; } diff --git a/src/libpakfire/include/pakfire/repo.h b/src/libpakfire/include/pakfire/repo.h index d9b31aab1..c9edbe6fe 100644 --- a/src/libpakfire/include/pakfire/repo.h +++ b/src/libpakfire/include/pakfire/repo.h @@ -30,7 +30,7 @@ struct pakfire_repo; #include #include -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); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index ba4ece6aa..a50a7d808 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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; } diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 44e0cef7a..68e984fd6 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -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) { diff --git a/src/libpakfire/request.c b/src/libpakfire/request.c index bb8bdc7c4..b50a802ae 100644 --- a/src/libpakfire/request.c +++ b/src/libpakfire/request.c @@ -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;