From: Michael Tremer Date: Mon, 21 Oct 2024 18:01:39 +0000 (+0000) Subject: archive: Simplify opening an archive X-Git-Tag: 0.9.30~971 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71acb81f481398ce75067e389f564778b8150ee4;p=pakfire.git archive: Simplify opening an archive 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 --- diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index f20f93c8b..8872a7875 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -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;