]> git.ipfire.org Git - pakfire.git/commitdiff
packager: Fix return codes
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Apr 2025 17:09:14 +0000 (17:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 16 Apr 2025 15:42:37 +0000 (15:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/packager.c

index 4af3a98a510f6412ad02a250e428f9c73aa63508..65991a3e9b7ab1d832f1c21c6070079e1b692c92 100644 (file)
@@ -429,10 +429,8 @@ int pakfire_packager_add_file(struct pakfire_packager* packager, struct pakfire_
        int r;
 
        // Check input
-       if (!file) {
-               errno = EINVAL;
-               return 1;
-       }
+       if (!file)
+               return -EINVAL;
 
        // Fetch path
        const char* path = pakfire_file_get_path(file);
@@ -440,21 +438,19 @@ int pakfire_packager_add_file(struct pakfire_packager* packager, struct pakfire_
        // Files cannot have an empty path
        if (!path || !*path) {
                ERROR(packager->ctx, "Cannot add a file with an empty path\n");
-               errno = EPERM;
-               return 1;
+               return -EPERM;
 
        // Hidden files cannot be added
        } else if (*path == '.') {
                ERROR(packager->ctx, "Hidden files cannot be added to a package: %s\n", path);
-               errno = EPERM;
-               return 1;
+               return -EPERM;
        }
 
        DEBUG(packager->ctx, "Adding file to payload: %s\n", path);
 
        // Detect the MIME type
        r = pakfire_file_detect_mimetype(file);
-       if (r)
+       if (r < 0)
                return r;
 
        // Overwrite a couple of things for source archives
@@ -555,16 +551,14 @@ int pakfire_packager_add_files(
 
 int pakfire_packager_add_scriptlet(struct pakfire_packager* packager,
                struct pakfire_scriptlet* scriptlet) {
-       if (!scriptlet) {
-               errno = EINVAL;
-               return 1;
-       }
+       if (!scriptlet)
+               return -EINVAL;
 
        // Extend array
        packager->scriptlets = reallocarray(packager->scriptlets,
                packager->num_scriptlets + 1, sizeof(*packager->scriptlets));
        if (!packager->scriptlets)
-               return 1;
+               return -errno;
 
        // Append scriptlet
        packager->scriptlets[packager->num_scriptlets++] = pakfire_scriptlet_ref(scriptlet);