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
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;
}
if (!sections)
return 0;
+ struct pakfire_repo* repo = NULL;
int r = 0;
// Walk through all sections
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;
}
}
}
-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) {
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;