}
}
-static struct pakfire_repo_appdata* pakfire_repo_setup_appdata(struct pakfire_repo* repo) {
+static int pakfire_repo_setup_appdata(struct pakfire_repo* self) {
struct pakfire_repo_appdata* appdata = NULL;
// Allocate appdata
- appdata = calloc(1, sizeof(*repo->appdata));
+ appdata = calloc(1, sizeof(*appdata));
if (!appdata)
- return NULL;
+ return -errno;
// Refresh Interval: Set to invalid
appdata->refresh = -1;
- return appdata;
+ // Store the pointer
+ self->appdata = self->repo->appdata = appdata;
+
+ return 0;
}
int pakfire_repo_create(struct pakfire_repo** repo,
struct pakfire* pakfire, const char* name) {
- int r = 1;
-
- // Reset repo pointer
- *repo = NULL;
-
- // Return existing repositories with the same name
- struct pakfire_repo* rep = pakfire_get_repo(pakfire, name);
- if (rep)
- goto SUCCESS;
+ struct pakfire_repo* self = NULL;
+ int r;
- // Create a new one
- rep = calloc(1, sizeof(*rep));
- if (!rep)
- return 1;
+ // Allocate some memory
+ self = calloc(1, sizeof(*self));
+ if (!self)
+ return -errno;
// Store a reference to the context
- rep->ctx = pakfire_ctx(pakfire);
+ self->ctx = pakfire_ctx(pakfire);
- rep->pakfire = pakfire_ref(pakfire);
- rep->nrefs = 1;
+ // Store a reference to Pakfire
+ self->pakfire = pakfire_ref(pakfire);
+ // Initialize the reference counter
+ self->nrefs = 1;
+
+ // Fetch the pool
Pool* pool = pakfire_get_solv_pool(pakfire);
// Allocate a libsolv repository
- rep->repo = repo_create(pool, name);
- if (!rep->repo) {
- ERROR(rep->ctx, "Could not allocate repo: %m\n");
+ self->repo = repo_create(pool, name);
+ if (!self->repo) {
+ ERROR(self->ctx, "Could not allocate repo: %m\n");
+ r = -errno;
goto ERROR;
}
// Allocate repository appdata
- rep->appdata = rep->repo->appdata = pakfire_repo_setup_appdata(rep);
- if (!rep->appdata) {
- ERROR(rep->ctx, "Could not setup repository appdata for %s\n", name);
+ r = pakfire_repo_setup_appdata(self);
+ if (r < 0) {
+ ERROR(self->ctx, "Could not setup repository appdata for %s: %s\n",
+ name, strerror(-r));
goto ERROR;
}
// Update the subpriority
- pakfire_repo_update_subpriority(rep);
+ pakfire_repo_update_subpriority(self);
// Setup/clear repository data
- r = pakfire_repo_clear(rep);
- if (r)
+ r = pakfire_repo_clear(self);
+ if (r < 0)
goto ERROR;
-SUCCESS:
- *repo = rep;
+ // Return the pointer
+ *repo = self;
return 0;
ERROR:
- pakfire_repo_free(rep, 1);
+ pakfire_repo_free(self, 1);
return r;
}
return pakfire_ref(repo->pakfire);
}
-int pakfire_repo_clear(struct pakfire_repo* repo) {
- repo_empty(repo->repo, 0);
+int pakfire_repo_clear(struct pakfire_repo* self) {
+ repo_empty(self->repo, 0);
return 0;
}