]> git.ipfire.org Git - pakfire.git/commitdiff
string: Correct handle return code of pakfire_string_set/_format
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 18 Aug 2022 10:43:00 +0000 (10:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 18 Aug 2022 10:43:00 +0000 (10:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
13 files changed:
src/libpakfire/archive.c
src/libpakfire/build.c
src/libpakfire/config.c
src/libpakfire/downloader.c
src/libpakfire/file.c
src/libpakfire/jail.c
src/libpakfire/key.c
src/libpakfire/packager.c
src/libpakfire/pakfire.c
src/libpakfire/progressbar.c
src/libpakfire/repo.c
src/libpakfire/request.c
tests/libpakfire/compress.c

index 3a0c8531b4f56091b67e91fe0fa69df5e1c1714e..53f8c50b78405cb67e7193e252c383655277aff5 100644 (file)
@@ -394,7 +394,7 @@ static int pakfire_archive_add_chksum(struct pakfire_archive* archive, const cha
 
        // Store path
        r = pakfire_string_set(chksum->path, path);
-       if (r < 0)
+       if (r)
                goto ERROR;
 
        // SHA512
@@ -878,8 +878,11 @@ PAKFIRE_EXPORT int pakfire_archive_extract(struct pakfire_archive* archive) {
        DEBUG(archive->pakfire, "Extracting %s\n", archive->path);
 
        // Set prefix for source packages
-       if (pakfire_package_is_source(pkg))
-               pakfire_string_format(prefix, "/usr/src/packages/%s", nevra);
+       if (pakfire_package_is_source(pkg)) {
+               r = pakfire_string_format(prefix, "/usr/src/packages/%s", nevra);
+               if (r)
+                       goto ERROR;
+       }
 
        // Open payload
        payload = pakfire_archive_open_payload(archive, &a, &size);
@@ -1140,14 +1143,14 @@ static int pakfire_archive_load_checksums_legacy_line(
                        // path
                        case 0:
                                r = pakfire_string_set(path, word);
-                               if (r < 0)
+                               if (r)
                                        return r;
                                break;
 
                        // hexdigest
                        case 1:
                                r = pakfire_string_set(hexdigest, word);
-                               if (r < 0)
+                               if (r)
                                        return r;
                                break;
 
@@ -1799,8 +1802,8 @@ static int pakfire_archive_append_signature(struct pakfire_archive* archive,
 
        // Make filename
        r = pakfire_string_format(path, "signatures/%s", pakfire_key_get_fingerprint(key));
-       if (r < 0)
-               return 1;
+       if (r)
+               return r;
 
        // Create a new file entry
        struct archive_entry* entry = archive_entry_new();
index 044bce819136872536040bbe0b01bb4bed43b7a2..fe4c96c747636bcc09ef112349e643e6ae5b64cd 100644 (file)
@@ -507,7 +507,7 @@ static int pakfire_build_package_add_scriptlets(struct pakfire_build* build,
 
        for (const char** type = pakfire_scriptlet_types; *type; type++) {
                r = pakfire_string_format(name, "scriptlet:%s", *type);
-               if (r < 0)
+               if (r)
                        return r;
 
                // Fetch the scriptlet
@@ -668,7 +668,7 @@ static int pakfire_build_stage(struct pakfire_build* build,
 
        // Prepare template for this stage
        int r = pakfire_string_format(template, TEMPLATE, stage);
-       if (r < 0)
+       if (r)
                return r;
 
        // Fetch the environment
@@ -819,7 +819,7 @@ static int pakfire_build_setup_cgroup(struct pakfire_build* build) {
 
        // Compose path
        r = pakfire_string_format(path, "pakfire/build-%s", build->_id);
-       if (r < 0) {
+       if (r) {
                ERROR(build->pakfire, "Could not compose path for cgroup: %m\n");
                return 1;
        }
@@ -1011,9 +1011,7 @@ PAKFIRE_EXPORT struct pakfire_build* pakfire_build_unref(struct pakfire_build* b
 
 PAKFIRE_EXPORT int pakfire_build_set_target(
                struct pakfire_build* build, const char* target) {
-       pakfire_string_set(build->target, target);
-
-       return 0;
+       return pakfire_string_set(build->target, target);
 }
 
 static int pakfire_build_install_packages(struct pakfire_build* build,
@@ -1154,8 +1152,8 @@ static int pakfire_build_read_makefile(struct pakfire_build* build,
 
        // Compose path to makefile
        r = pakfire_string_format(makefile, "/usr/src/packages/%s/%s.nm", nevra, name);
-       if (r < 0)
-               return 1;
+       if (r)
+               return r;
 
        // Make it absolute
        r = pakfire_make_path(build->pakfire, path, makefile);
index c9b3b6c785628b80d6451407f67b551c8d84da47..ad1095f73924f0b182231d4c08577eb6efb88018 100644 (file)
@@ -104,17 +104,13 @@ static struct pakfire_config_entry* pakfire_config_create_entry(
 
        // Store section
        r = pakfire_string_set(entry->section, section);
-       if (r < 0) {
-               errno = ENOBUFS;
+       if (r)
                goto ERROR;
-       }
 
        // Store key
        r = pakfire_string_set(entry->key, key);
-       if (r < 0) {
-               errno = ENOBUFS;
+       if (r)
                goto ERROR;
-       }
 
        // Append it to the list of entries
        STAILQ_INSERT_TAIL(&config->entries, entry, nodes);
@@ -170,11 +166,7 @@ int pakfire_config_set(struct pakfire_config* config,
        }
 
        // Store the value
-       int r = pakfire_string_set(entry->value, value);
-       if (r < 0)
-               return r;
-
-       return 0;
+       return pakfire_string_set(entry->value, value);
 }
 
 const char* pakfire_config_get(struct pakfire_config* config,
index 70605950fe0cef2e16ba7f17792391bfa8391d1a..36a01fe7f8804f9660cc3751911dc2d77a1d42d6 100644 (file)
@@ -756,7 +756,7 @@ static int pakfire_downloader_prepare_transfer(struct pakfire_downloader* downlo
        if (!transfer->f) {
                // Make path for the temporary file (must be on the same file system)
                r = pakfire_string_format(transfer->tempfile, "%s.XXXXXX", transfer->path);
-               if (r < 0)
+               if (r)
                        return 1;
 
                transfer->f = pakfire_mktemp(transfer->tempfile);
index 7120ef44c559ff1628fc2ab2ca71970d6c8896c1..43497f9729d6b9b02f39e44be9860c3994b35cdc 100644 (file)
@@ -526,7 +526,7 @@ int pakfire_file_cleanup(struct pakfire_file* file) {
 
        // Create a working copy of abspath
        r = pakfire_string_set(path, file->abspath);
-       if (r < 0)
+       if (r)
                return r;
 
        // See how many levels this file has
index f2aac5fd677fa8d218ff2854cfe154ef111e5a76..3686c0a4df127843348ee33827e38f59b3c272d3 100644 (file)
@@ -925,16 +925,16 @@ PAKFIRE_EXPORT int pakfire_jail_bind(struct pakfire_jail* jail,
 
        // Copy source
        r = pakfire_string_set(mp->source, source);
-       if (r < 0) {
+       if (r) {
                ERROR(jail->pakfire, "Could not copy source: %m\n");
-               return 1;
+               return r;
        }
 
        // Copy target
        r = pakfire_string_set(mp->target, target);
-       if (r < 0) {
+       if (r) {
                ERROR(jail->pakfire, "Could not copy target: %m\n");
-               return 1;
+               return r;
        }
 
        // Copy flags
@@ -998,8 +998,8 @@ static int pakfire_jail_setup_uid_mapping(struct pakfire_jail* jail, pid_t pid)
 
        // Make path
        r = pakfire_string_format(path, "/proc/%d/uid_map", pid);
-       if (r < 0)
-               return 1;
+       if (r)
+               return r;
 
        DEBUG(jail->pakfire, "Mapping UID range (%u - %lu)\n",
                subuid->id, subuid->id + subuid->length);
@@ -1022,8 +1022,8 @@ static int pakfire_jail_setup_gid_mapping(struct pakfire_jail* jail, pid_t pid)
 
        // Make path
        r = pakfire_string_format(path, "/proc/%d/gid_map", pid);
-       if (r < 0)
-               return 1;
+       if (r)
+               return r;
 
        DEBUG(jail->pakfire, "Mapping GID range (%u - %lu)\n",
                subgid->id, subgid->id + subgid->length);
@@ -1037,8 +1037,8 @@ static int pakfire_jail_setgroups(struct pakfire_jail* jail, pid_t pid) {
 
        // Make path
        r = pakfire_string_format(path, "/proc/%d/setgroups", pid);
-       if (r < 0)
-               return 1;
+       if (r)
+               return r;
 
        // Open file for writing
        FILE* f = fopen(path, "w");
index 66f52ac03aa14eddbb35666e454f4fe81e9c4cfe..50b83dd4725fe9fef9478d69ce2737cc6ca81b1e 100644 (file)
@@ -378,7 +378,7 @@ static int pakfire_key_write_to_keystore(struct pakfire_key* key) {
 
        // Make path
        int r = pakfire_string_format(path, "%s/%s.key", keystore_path, fpr);
-       if (r < 0)
+       if (r)
                return r;
 
        // Create parent directory
index ad10c1afe91fcf2cae61d1c635ce2a88c9b5d620..e18bf54af218c84684fe768d7982d3ae5fa4ee7b 100644 (file)
@@ -571,7 +571,7 @@ static int pakfire_packager_write_scriptlet(struct pakfire_packager* packager,
 
        // Make filename
        r = pakfire_string_format(filename, "scriptlet/%s", type);
-       if (r < 0)
+       if (r)
                return r;
 
        // Fetch scriptlet
@@ -749,7 +749,7 @@ int pakfire_packager_finish_to_directory(struct pakfire_packager* packager,
 
        // Make the package path
        r = pakfire_string_format(path, "%s/%s", target, filename);
-       if (r < 0)
+       if (r)
                goto ERROR;
 
        // Create the parent directory
@@ -759,7 +759,7 @@ int pakfire_packager_finish_to_directory(struct pakfire_packager* packager,
 
        // Create a temporary file in the target directory
        r = pakfire_string_format(tmppath, "%s.XXXXXX", path);
-       if (r < 0)
+       if (r)
                goto ERROR;
 
        // Create a temporary result file
index a13a861e6adb3091a8827e45d6c6291dcd0e84e8..8fcd7a09f335dc190beee3cb25bdf4a7b84dac50 100644 (file)
@@ -636,7 +636,7 @@ static int pakfire_read_os_release(struct pakfire* pakfire) {
                        continue;
 
                // Catch any errors
-               if (r < 0)
+               if (r)
                        goto ERROR;
        }
 
index 01edfcb34575f197ba5efe6105c1ff29d83c9a02..ce9211c22a3072cab0b4e194bb4bc6f09789d048 100644 (file)
@@ -450,7 +450,7 @@ PAKFIRE_EXPORT int pakfire_progressbar_add_string(struct pakfire_progressbar* p,
 static const char* pakfire_progressbar_counter(struct pakfire_progressbar* p,
                struct pakfire_progressbar_widget* widget, unsigned int width, void* data) {
        int r = pakfire_string_format(widget->buffer, "%lu/%lu", p->value, p->value_max);
-       if (r < 0)
+       if (r)
                return NULL;
 
        return widget->buffer;
@@ -467,7 +467,7 @@ static const char* pakfire_progressbar_percentage(struct pakfire_progressbar* p,
        double percentage = p->value * 100.0 / p->value_max;
 
        int r = pakfire_string_format(widget->buffer, "%3.0f%%", percentage);
-       if (r < 0)
+       if (r)
                return NULL;
 
        return widget->buffer;
@@ -526,7 +526,7 @@ static const char* pakfire_progressbar_timer(struct pakfire_progressbar* p,
                return NULL;
 
        int r = pakfire_string_format(widget->buffer, "%02lu:%02lu", t / 60, t % 60);
-       if (r < 0)
+       if (r)
                return NULL;
 
        return widget->buffer;
@@ -553,14 +553,14 @@ static const char* pakfire_progressbar_eta(struct pakfire_progressbar* p,
        // Print a placeholder when we haven't started yet
        if (p->value == 0) {
                r = pakfire_string_format(widget->buffer, "%-5s: --:--:--", _("ETA"));
-               if (r < 0)
+               if (r)
                        return NULL;
 
        // Show total time when finished
        } else if (p->status == PAKFIRE_PROGRESSBAR_FINISHED) {
                r = pakfire_string_format(widget->buffer, "%-5s: %02lu:%02lu",
                        _("Time"), t / 60, t % 60);
-               if (r < 0)
+               if (r)
                        return NULL;
 
        // Calculate the ETA
@@ -569,7 +569,7 @@ static const char* pakfire_progressbar_eta(struct pakfire_progressbar* p,
 
                r = pakfire_string_format(widget->buffer, "%-5s: %02lu:%02lu",
                        _("ETA"), eta / 60, eta % 60);
-               if (r < 0)
+               if (r)
                        return NULL;
        }
 
index 138aa5427a297eb23987abccd86c1a6b3bb75d26..d0801a989f1b7715057dcecd02e07e1717c35ffb 100644 (file)
@@ -1141,7 +1141,7 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, const char* pa
 
        // Create path for a temporary database export file
        r = pakfire_string_format(tmp, "%s/repodata/.pakfire-solv.XXXXXX", path);
-       if (r < 0)
+       if (r)
                return r;
 
        // Create a temporary file to write to
@@ -1171,7 +1171,7 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, const char* pa
 
        // Make final database path
        r = pakfire_string_format(database, "%s/repodata/%s", path, filename);
-       if (r < 0) {
+       if (r) {
                ERROR(repo->pakfire, "Could not join database path: %m\n");
                goto ERROR;
        }
@@ -1274,7 +1274,7 @@ static int pakfire_repo_write_metadata(struct pakfire_repo* repo) {
 
        // Make path to repomd.json
        r = pakfire_string_format(repomd_path, "%s/repodata/repomd.json", path);
-       if (r < 0)
+       if (r)
                goto ERROR;
 
        // Open repomd.json for writing
@@ -1326,7 +1326,7 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
 
        // Prefix path with file:// to form baseurl
        r = pakfire_string_format(baseurl, "file://%s", path);
-       if (r < 0)
+       if (r)
                return 1;
 
        // Create a new temporary repository at path
index 4642db6578561885f58961ee1a8791a426bc55ef..040ce4a72d81d22fe27ae609edbf603d9b9827cc 100644 (file)
@@ -114,7 +114,7 @@ static void pakfire_request_lock_running_kernel(struct pakfire_request* request)
        DEBUG(request->pakfire, "Locking running kernel %s\n", utsname.release);
 
        r = pakfire_string_format(buffer, "kernel(%s)", utsname.release);
-       if (r < 0)
+       if (r)
                return;
 
        Pool* pool = pakfire_get_solv_pool(request->pakfire);
index 880f085d366091455671cc10dd4f84820c4b4193..3504628d1bec94fcb28030b274d8591e6f7c1474 100644 (file)
@@ -38,8 +38,7 @@ static int read_test(const struct test* t,
        char path[PATH_MAX];
        char buffer[1024];
 
-       r = pakfire_string_format(path, "%s/%s", TEST_SRC_PATH, file);
-       ASSERT(r >= 0);
+       ASSERT_SUCCESS(pakfire_string_format(path, "%s/%s", TEST_SRC_PATH, file));
 
        // Open file
        ASSERT(f = fopen(path, "r"));