]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Tidy up writing repository configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 10:54:05 +0000 (10:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 10:54:05 +0000 (10:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/repo.c

index 2d4c7568f9644dcf32b856d7139360c1c8c3147e..b172b91fd1c9672faabd813514a5b92b29cee446 100644 (file)
@@ -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(&section, "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;
                }
        }