]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Improve error handling when opening an archive
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 19:22:48 +0000 (19:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 19:22:48 +0000 (19:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c

index b00474a8ef5248d7a8d528af3822d66c33482a47..f1f85780e965823b44d59708b0cbe8058f17ae71 100644 (file)
@@ -493,7 +493,9 @@ static int pakfire_archive_try_open(struct pakfire_archive* archive, const char*
        CTX_DEBUG(archive->ctx, "Opening archive %s\n", path);
 
        // Store path
-       pakfire_string_set(archive->path, path);
+       r = pakfire_string_set(archive->path, path);
+       if (r < 0)
+               return r;
 
        // Open the file (and keep the file descriptor open)
        archive->f = fopen(archive->path, "r");
@@ -502,27 +504,22 @@ static int pakfire_archive_try_open(struct pakfire_archive* archive, const char*
 
        // Let the kernel know, that we will read the file sequentially
        r = posix_fadvise(fileno(archive->f), 0, 0, POSIX_FADV_SEQUENTIAL);
-       if (r) {
-               CTX_ERROR(archive->ctx, "posix_fadvise() failed: %m\n");
-               goto ERROR;
-       }
+       if (r)
+               CTX_DEBUG(archive->ctx, "posix_fadvise() failed. Ignoring: %m\n");
 
        // Call stat() on f
        r = fstat(fileno(archive->f), &archive->stat);
        if (r) {
                CTX_ERROR(archive->ctx, "Could not stat archive: %m\n");
-               goto ERROR;
+               return r;
        }
 
        // Read all package metadata
        r = pakfire_archive_read_metadata(archive);
-       if (r) {
-               CTX_ERROR(archive->ctx, "Could not open archive: %s\n", strerror(-r));
-               goto ERROR;
-       }
+       if (r < 0)
+               return r;
 
-ERROR:
-       return r;
+       return 0;
 }
 
 PAKFIRE_EXPORT int pakfire_archive_open(struct pakfire_archive** archive, struct pakfire* pakfire, const char* path) {