]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Return better error codes when archives could not be opened
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 14:59:09 +0000 (14:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 14:59:09 +0000 (14:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c

index 197293a0fe8b2ceaa3e3aa54bbe192136479ac48..8ef50e948cfbf30e519656d2b9948c5a010aed82 100644 (file)
@@ -166,7 +166,7 @@ static int pakfire_archive_walk(struct pakfire_archive* archive,
        // Open the archive file
        struct archive* a = open_archive(archive, NULL);
        if (!a)
-               return 1;
+               return -errno;
 
        // Walk through the archive
        r = pakfire_walk(archive->pakfire, a, callback, filter_callback, data);
@@ -291,7 +291,7 @@ static int pakfire_archive_parse_format(struct pakfire_archive* archive,
                default:
                        ERROR(archive->pakfire, "This version of Pakfire does not support "
                                "archive format %d\n", archive->format);
-                       return -EINVAL;
+                       return -ENOTSUP;
        }
 
        DEBUG(archive->pakfire, "Archive format is %d\n", archive->format);
@@ -422,13 +422,13 @@ static int pakfire_archive_read_metadata(struct pakfire_archive* archive) {
        // Check if we could successfully read something
        if (!archive->format) {
                ERROR(archive->pakfire, "Archive has an unknown format\n");
-               return -EINVAL;
+               return -ENOMSG;
        }
 
        // Check if we have read some metadata
        if (!archive->metadata) {
                ERROR(archive->pakfire, "Archive has no metadata\n");
-               return -EINVAL;
+               return -ENOMSG;
        }
 
        return 0;
@@ -449,7 +449,7 @@ static int pakfire_archive_try_open(struct pakfire_archive* archive, const char*
        // Open the file (and keep the file descriptor open)
        archive->f = fopen(archive->path, "r");
        if (!archive->f)
-               return 1;
+               return -errno;
 
        // Let the kernel know, that we will read the file sequentially
        r = posix_fadvise(fileno(archive->f), 0, 0, POSIX_FADV_SEQUENTIAL);
@@ -468,7 +468,7 @@ static int pakfire_archive_try_open(struct pakfire_archive* archive, const char*
        // Read all package metadata
        r = pakfire_archive_read_metadata(archive);
        if (r) {
-               ERROR(archive->pakfire, "Could not open archive: %m\n");
+               ERROR_ERRNO(archive->pakfire, r, "Could not open archive: %m\n");
                goto ERROR;
        }