]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Avoid calling stat() on every archive
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Apr 2021 11:26:14 +0000 (11:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Apr 2021 11:26:14 +0000 (11:26 +0000)
The result is only used for the file size

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

index 26d77e2607163b4201c3323a40a1cfcd7e794c3b..d488ebd5bd72629cd0018f277880c1be92a5f891 100644 (file)
@@ -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;
 }
 
 /*