From: Michael Tremer Date: Wed, 7 Apr 2021 11:26:14 +0000 (+0000) Subject: archive: Avoid calling stat() on every archive X-Git-Tag: 0.9.28~1285^2~405 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=165b2786f6317de8e62d79ba5bf2f70c831f3af6;p=pakfire.git archive: Avoid calling stat() on every archive The result is only used for the file size Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index 26d77e260..d488ebd5b 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -65,7 +65,6 @@ struct _PakfireArchive { int nrefs; char path[PATH_MAX]; - struct stat stat; // metadata int format; @@ -636,18 +635,9 @@ static int pakfire_archive_try_open(PakfireArchive archive, const char* path) { // Store path pakfire_string_set(archive->path, path); - // Stat the file and store the result - int r = stat(archive->path, &archive->stat); - if (r) { - ERROR(archive->pakfire, "Could not stat %s: %s\n", - archive->path, strerror(errno)); - - goto ERROR; - } - // Open the archive file for reading. struct archive* a = NULL; - r = archive_open(archive, &a); + int r = archive_open(archive, &a); if (r) goto ERROR; @@ -1195,7 +1185,17 @@ PAKFIRE_EXPORT const char* pakfire_archive_verify_strerror(pakfire_archive_verif } PAKFIRE_EXPORT size_t pakfire_archive_get_size(PakfireArchive archive) { - return archive->stat.st_size; + struct stat buf; + + int r = stat(archive->path, &buf); + if (r) { + ERROR(archive->pakfire, "Could not stat %s: %s\n", + archive->path, strerror(errno)); + + return -1; + } + + return buf.st_size; } /*