]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
archive: Fix reading filelists/extraction on newer formats
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Mar 2023 15:59:53 +0000 (15:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Mar 2023 16:35:35 +0000 (16:35 +0000)
Fixes: #12995 - pakfire extracts meta files in archives
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c
src/libpakfire/compress.c
src/libpakfire/include/pakfire/compress.h
src/libpakfire/snapshot.c
tests/libpakfire/archive.c

index 413c6a31ce86ffcde88d00b3fec0fdc24b945f1f..f1e43c5ca809c99b3e3a381d1e49ef97b2a9f35d 100644 (file)
@@ -534,22 +534,24 @@ struct pakfire_archive_read {
 
 static int __pakfire_archive_filter_payload(struct pakfire* pakfire,
                struct archive* a, struct archive_entry* entry, void* p) {
-       struct pakfire_archive_read* _read = (struct pakfire_archive_read*)p;
-       struct pakfire_archive* archive = _read->archive;
+       const char* path = archive_entry_pathname(entry);
+       if (!path)
+               return PAKFIRE_WALK_ERROR;
 
-       const char* path = NULL;
+       switch (*path) {
+               case 'p':
+                       if (strcmp(path, "pakfire-format") == 0)
+                               return PAKFIRE_WALK_SKIP;
 
-       // Format >= 6
-       if (archive->format >= 6) {
-               path = archive_entry_pathname(entry);
+                       // Fallthrough
 
-               // Skip any hidden files
-               if (path && *path == '.')
-                       return ARCHIVE_RETRY;
-       }
+               case '.':
+                       return PAKFIRE_WALK_SKIP;
 
-       // Otherwise permit reading any files
-       return ARCHIVE_OK;
+               // The first file that isn't metadata was found, so we can end here
+               default:
+                       return PAKFIRE_WALK_END;
+       }
 }
 
 static int __pakfire_archive_read_payload(struct pakfire* pakfire,
@@ -727,7 +729,7 @@ static int __pakfire_archive_extract(struct pakfire_archive* archive, int flags)
 
        // Extract
        r = pakfire_extract(archive->pakfire, a, archive->stat.st_size,
-               filelist, prefix, nevra, flags);
+               filelist, prefix, nevra, __pakfire_archive_filter_payload, flags);
        if (r)
                goto ERROR;
 
index b39c7f9a105eece0fb4ea422441cb69f4d4915ad..5d66474a7e17f6cd6c1fb8f91627635a7957332e 100644 (file)
@@ -569,6 +569,13 @@ int pakfire_walk(struct pakfire* pakfire, struct archive* archive,
                                        DEBUG(pakfire, "Filter callback sent SKIP\n");
                                        continue;
 
+                               case PAKFIRE_WALK_END:
+                                       DEBUG(pakfire, "Filter callback sent END\n");
+
+                                       // Clear the callback function
+                                       filter_callback = NULL;
+                                       break;
+
                                // Raise any other errors
                                default:
                                        DEBUG(pakfire, "Filter callback returned an error: %d\n", r);
@@ -760,7 +767,8 @@ ERROR:
 
 int pakfire_extract(struct pakfire* pakfire, struct archive* archive,
                size_t size, struct pakfire_filelist* filelist,
-               const char* prefix, const char* message, int flags) {
+               const char* prefix, const char* message,
+               pakfire_walk_filter_callback filter_callback, int flags) {
        int r = 1;
 
        // Use an empty string if no prefix set
@@ -811,7 +819,7 @@ int pakfire_extract(struct pakfire* pakfire, struct archive* archive,
        }
 
        // Walk through the entire archive
-       r = pakfire_walk(pakfire, archive, __pakfire_extract, NULL, &data);
+       r = pakfire_walk(pakfire, archive, __pakfire_extract, filter_callback, &data);
        if (r)
                goto ERROR;
 
index 3ed1bc2a34537bfd50a13cf1c7c3d1cad2a0c8ff..ce6e760fcb2d1ef47d67814fadacd86cc3634abd 100644 (file)
@@ -52,6 +52,9 @@ enum pakfire_walk_codes {
 
        // Request the next entry (only in filter callback)
        PAKFIRE_WALK_SKIP  = -20,
+
+       // Like PAKFIRE_WALK_OK, but the callback will not be called again
+       PAKFIRE_WALK_END   = -30,
 };
 
 int pakfire_walk(struct pakfire* pakfire, struct archive* archive,
@@ -66,7 +69,8 @@ enum pakfire_extract_flags {
 
 int pakfire_extract(struct pakfire* pakfire, struct archive* archive,
        size_t size, struct pakfire_filelist* filelist, const char* prefix,
-       const char* message, int flags);
+       const char* message, pakfire_walk_filter_callback filter_callback,
+       int flags);
 
 // Compress
 enum pakfire_compress_flags {
index 6a9916296e10563fa6c0a18b2f997ce3a0194bc7..ac9fbfcaa642c60e8726fd55bad4bded6d98364c 100644 (file)
@@ -182,7 +182,7 @@ static int pakfire_snapshot_extract(struct pakfire* pakfire, const char* path) {
 
        // Extract snapshot
        r = pakfire_extract(pakfire, archive, st.st_size, NULL, NULL,
-                       _("Extracting snapshot..."), PAKFIRE_EXTRACT_SHOW_THROUGHPUT);
+                       _("Extracting snapshot..."), NULL, PAKFIRE_EXTRACT_SHOW_THROUGHPUT);
        if (r)
                goto ERROR;
 
index d3ac1f0c889c8e6d565631b4eda403a6905ce46d..29926c24dc69313f81df2c6b70ada18f53072b5c 100644 (file)
@@ -254,10 +254,7 @@ int main(int argc, const char* argv[]) {
        testsuite_add_test(test_read);
 #endif
        testsuite_add_test(test_copy);
-#warning The filelist is being delivered incorrectly
-#if 0
        testsuite_add_test(test_filelist);
-#endif
        testsuite_add_test(test_extract);
        testsuite_add_test(test_import);