From: Michael Tremer Date: Sat, 1 Feb 2025 14:50:18 +0000 (+0000) Subject: repo: Refactor importing repositories X-Git-Tag: 0.9.30~194 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65001f7f274b1d001e254530888dd86b37b83513;p=pakfire.git repo: Refactor importing repositories Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index de20947a..ab3bccd7 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -312,10 +312,10 @@ ERROR: 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:")) @@ -328,67 +328,76 @@ static int __pakfire_repo_import( struct pakfire_config* config, const char* sec 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; }