]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Refactor walking through archive
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Apr 2021 16:09:47 +0000 (16:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Apr 2021 16:09:47 +0000 (16:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c

index 1b434db403e2ac2d83836299a3c6164c5347e692..d6c1183ca95d4d53c466d76604a0b50e28d53800 100644 (file)
@@ -570,26 +570,30 @@ static int pakfire_archive_parse_entry_scriptlet(PakfireArchive archive,
 
 static int pakfire_archive_walk(PakfireArchive archive,
                int (*callback)(PakfireArchive archive, struct archive* a, struct archive_entry* e, const char* pathname)) {
+       struct archive* a;
        struct archive_entry* e;
-       int r = 0;
 
        // Open the archive file
-       struct archive* a;
-       r = archive_open(archive, &a);
+       int r = archive_open(archive, &a);
        if (r)
                return r;
 
        // Walk through the archive
-       int ret;
-       while ((ret = archive_read_next_header(a, &e)) == ARCHIVE_OK) {
+       while (1) {
+               r = archive_read_next_header(a, &e);
+               if (r)
+                       break;
+
+               // Fetch the filename
                const char* pathname = archive_entry_pathname(e);
 
+               // Run callback
                r = callback(archive, a, e, pathname);
                if (r)
                        break;
        }
 
-       // Close the archive again
+       // Close the archive
        archive_read_free(a);
 
        return r;