]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Simplify opening an archive
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Oct 2024 18:01:39 +0000 (18:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Oct 2024 18:01:39 +0000 (18:01 +0000)
There is nothing special needed now we clone the file descriptors. So
this is mainly just to make the file sticky.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c

index f20f93c8b524e71d5e19c99b8554fd4b8020dbe4..8872a78753e404a821ef851b1c3e7fb6333f4a45 100644 (file)
@@ -658,32 +658,6 @@ ERROR:
        return r;
 }
 
-static int pakfire_archive_try_open(struct pakfire_archive* archive) {
-       int r;
-
-       CTX_DEBUG(archive->ctx, "Opening archive %s\n", archive->path);
-
-       // Open the file (and keep the file descriptor open)
-       archive->f = fopen(archive->path, "r");
-       if (!archive->f)
-               return -errno;
-
-       // 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_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");
-               return -errno;
-       }
-
-       // Read all package metadata
-       return pakfire_archive_read_metadata(archive);
-}
-
 PAKFIRE_EXPORT int pakfire_archive_open(struct pakfire_archive** archive,
                struct pakfire* pakfire, const char* path) {
        struct pakfire_archive* a = NULL;
@@ -708,8 +682,26 @@ PAKFIRE_EXPORT int pakfire_archive_open(struct pakfire_archive** archive,
        if (r < 0)
                goto ERROR;
 
-       // Try to open the archive
-       r = pakfire_archive_try_open(a);
+       CTX_DEBUG(a->ctx, "Opening archive %s\n", a->path);
+
+       // Open the file (and keep the file descriptor open)
+       a->f = fopen(a->path, "r");
+       if (!a->f) {
+               CTX_ERROR(a->ctx, "Could not open archive %s: %m\n", a->path);
+               r = -errno;
+               goto ERROR;
+       }
+
+       // Call stat() on f
+       r = fstat(fileno(a->f), &a->stat);
+       if (r < 0) {
+               CTX_ERROR(a->ctx, "Could not stat archive %s: %m\n", a->path);
+               r = -errno;
+               goto ERROR;
+       }
+
+       // Read all package metadata
+       r = pakfire_archive_read_metadata(a);
        if (r < 0)
                goto ERROR;