From a4fb4690c0d0f39dcdfd0890f9094b6abfc19381 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 5 Feb 2025 10:54:05 +0000 Subject: [PATCH] repo: Tidy up writing repository configuration Signed-off-by: Michael Tremer --- src/pakfire/repo.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index 2d4c7568..b172b91f 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -1727,19 +1727,17 @@ int pakfire_repo_set_mirrorlist_url(struct pakfire_repo* repo, const char* url) } int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f) { + struct pakfire_config* config = NULL; + struct pakfire_key* key = NULL; + char* section = NULL; + char* buffer = NULL; + size_t length = 0; int r; // Do nothing for the installed repository if (pakfire_repo_is_installed_repo(repo)) return 0; - struct pakfire_config* config = NULL; - char* section = NULL; - - struct pakfire_key* key = NULL; - char* buffer = NULL; - size_t length = 0; - // Create section name r = asprintf(§ion, "repo:%s", pakfire_repo_get_name(repo)); if (r < 0) @@ -1747,15 +1745,15 @@ int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f) { // Create a new configuration r = pakfire_config_create(&config); - if (r) + if (r < 0) goto ERROR; // Description const char* description = pakfire_repo_get_description(repo); if (description) { r = pakfire_config_set(config, section, "description", description); - if (r) { - ERROR(repo->ctx, "Could not set description: %m\n"); + if (r < 0) { + ERROR(repo->ctx, "Could not set description: %s\n", strerror(-r)); goto ERROR; } } @@ -1763,8 +1761,8 @@ int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f) { // Disabled? if (!pakfire_repo_get_enabled(repo)) { r = pakfire_config_set(config, section, "enabled", "0"); - if (r) { - ERROR(repo->ctx, "Could not set enabled: %m\n"); + if (r < 0) { + ERROR(repo->ctx, "Could not set enabled: %s\n", strerror(-r)); goto ERROR; } } @@ -1773,8 +1771,8 @@ int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f) { const char* baseurl = pakfire_repo_get_baseurl(repo); if (baseurl) { r = pakfire_config_set(config, section, "baseurl", baseurl); - if (r) { - ERROR(repo->ctx, "Could not set base URL: %m\n"); + if (r < 0) { + ERROR(repo->ctx, "Could not set base URL: %s\n", strerror(-r)); goto ERROR; } } @@ -1785,8 +1783,8 @@ int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f) { r = pakfire_config_set(config, section, "refresh", refresh); free(refresh); - if (r) { - ERROR(repo->ctx, "Could not set refresh interval: %m\n"); + if (r < 0) { + ERROR(repo->ctx, "Could not set refresh interval: %s\n", strerror(-r)); goto ERROR; } } @@ -1795,8 +1793,8 @@ int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f) { const char* mirrorlist = pakfire_repo_get_mirrorlist_url(repo); if (mirrorlist) { r = pakfire_config_set(config, section, "mirrors", mirrorlist); - if (r) { - ERROR(repo->ctx, "Could not set mirrors: %m\n"); + if (r < 0) { + ERROR(repo->ctx, "Could not set mirrors: %s\n", strerror(-r)); goto ERROR; } } @@ -1821,8 +1819,8 @@ int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f) { unsigned int priority = pakfire_repo_get_priority(repo); if (priority) { r = pakfire_config_set_format(config, section, "priority", "%u", priority); - if (r) { - ERROR(repo->ctx, "Could not set priority: %m\n"); + if (r < 0) { + ERROR(repo->ctx, "Could not set priority: %s\n", strerror(-r)); goto ERROR; } } -- 2.39.5