From: Michael Tremer Date: Sat, 12 Oct 2024 19:22:48 +0000 (+0000) Subject: archive: Improve error handling when opening an archive X-Git-Tag: 0.9.30~1050 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5998a6558b5957b33df89996c6b6a69daef2a6a;p=pakfire.git archive: Improve error handling when opening an archive Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index b00474a8e..f1f85780e 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -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) {