return r;
}
-static int __pakfire_repo_import( struct pakfire_config* config, const char* section, void* p) {
- struct pakfire* pakfire = (struct pakfire*)p;
- struct pakfire_repo* repo = NULL;
- int r = 0;
+static int __pakfire_repo_import(struct pakfire_config* config, const char* section, void* data) {
+ struct pakfire_repo* self = NULL;
+ struct pakfire* pakfire = data;
+ int r;
// Ignore if the section does not start with "repo:"
if (!pakfire_string_startswith(section, "repo:"))
if (!*name)
return 0;
- // Fetch context
- struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
-
- DEBUG(ctx, "Creating repository %s\n", name);
-
// Create a new repository
- r = pakfire_repo_create(&repo, pakfire, name);
- if (r < 0) {
- ERROR(ctx, "Could not create repository '%s': %m\n", name);
+ r = pakfire_repo_create(&self, pakfire, name);
+ if (r < 0)
goto ERROR;
- }
// Make the static analyzer happy
- if (!repo)
+ if (!self)
goto ERROR;
// Enabled
- int enabled = pakfire_config_get_bool(config, section, "enabled", 1);
- pakfire_repo_set_enabled(repo, enabled);
+ pakfire_repo_set_enabled(self, pakfire_config_get_bool(config, section, "enabled", 1));
// Priority
int priority = pakfire_config_get_int(config, section, "priority", 0);
if (priority)
- pakfire_repo_set_priority(repo, priority);
+ pakfire_repo_set_priority(self, priority);
// Description
const char* description = pakfire_config_get(config, section, "description", NULL);
- if (description)
- pakfire_repo_set_description(repo, description);
+ if (description) {
+ r = pakfire_repo_set_description(self, description);
+ if (r < 0) {
+ ERROR(self->ctx, "Could not set description: %s\n", strerror(-r));
+ goto ERROR;
+ }
+ }
// baseurl
const char* baseurl = pakfire_config_get(config, section, "baseurl", NULL);
if (baseurl) {
- r = pakfire_repo_set_baseurl(repo, baseurl);
- if (r)
+ r = pakfire_repo_set_baseurl(self, baseurl);
+ if (r) {
+ ERROR(self->ctx, "Could not set base URL: %s\n", strerror(-r));
goto ERROR;
+ }
}
// Refresh Interval
const char* refresh = pakfire_config_get(config, section, "refresh", NULL);
- if (refresh)
- repo->appdata->refresh = pakfire_string_parse_interval(refresh);
+ if (refresh) {
+ self->appdata->refresh = r = pakfire_string_parse_interval(refresh);
+ if (r < 0) {
+ ERROR(self->ctx, "Could not set refresh interval: %s\n", strerror(-r));
+ goto ERROR;
+ }
+ }
// mirrors
const char* mirrors = pakfire_config_get(config, section, "mirrors", NULL);
- if (mirrors)
- pakfire_repo_set_mirrorlist_url(repo, mirrors);
+ if (mirrors) {
+ r = pakfire_repo_set_mirrorlist_url(self, mirrors);
+ if (r < 0) {
+ ERROR(self->ctx, "Could not set the mirrorlist URL: %s\n", strerror(-r));
+ goto ERROR;
+ }
+ }
// Key
const char* key = pakfire_config_get(config, section, "key", NULL);
if (key) {
- r = pakfire_repo_import_key(repo, key);
- if (r)
+ r = pakfire_repo_import_key(self, key);
+ if (r) {
+ ERROR(self->ctx, "Could not set the key: %s\n", strerror(-r));
goto ERROR;
+ }
}
ERROR:
- if (repo)
- pakfire_repo_unref(repo);
- if (ctx)
- pakfire_ctx_unref(ctx);
+ if (self)
+ pakfire_repo_unref(self);
return r;
}