]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Align the disk reader with the writer
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Oct 2024 01:44:39 +0000 (01:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Oct 2024 02:13:10 +0000 (02:13 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/filelist.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/packager.c
src/libpakfire/pakfire.c

index 5d8194a0abf2ca6351ca40926e4f4f7bc25232d6..be59048fda802ab445df71fce7d338d9924bd745 100644 (file)
@@ -341,7 +341,7 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root,
        }
 
        // Create a new disk reader
-       reader = pakfire_make_archive_disk_reader(list->pakfire, 1);
+       reader = pakfire_get_disk_reader(list->pakfire);
        if (!reader)
                goto ERROR;
 
@@ -400,9 +400,6 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root,
        }
 
 ERROR:
-       if (reader)
-               archive_read_free(reader);
-
        return r;
 }
 
index ecceb176482a2f5a08badf924e87fc8cf03a5d72..02bf2755eaa29b8eb57756a689dbd21e1a374145 100644 (file)
@@ -160,7 +160,7 @@ int pakfire_repo_walk(struct pakfire* pakfire,
        pakfire_repo_walk_callback callback, void* p);
 
 // Archive helpers
-struct archive* pakfire_make_archive_disk_reader(struct pakfire* pakfire, int internal);
+struct archive* pakfire_get_disk_reader(struct pakfire* pakfire);
 struct archive* pakfire_get_disk_writer(struct pakfire* pakfire);
 
 #endif
index 69ada58012d480e3e45e4aa5751909eaa0d1eed7..0a91d89445b6b193a5e7f676ea3a545b4a7d9037 100644 (file)
@@ -76,9 +76,6 @@ static void pakfire_packager_free(struct pakfire_packager* packager) {
                free(packager->scriptlets);
        }
 
-       if (packager->reader)
-               archive_read_free(packager->reader);
-
        if (packager->filelist)
                pakfire_filelist_unref(packager->filelist);
        pakfire_package_unref(packager->pkg);
@@ -139,7 +136,7 @@ int pakfire_packager_create(struct pakfire_packager** packager,
        pakfire_package_set_num(pkg, PAKFIRE_PKG_BUILD_TIME, p->time_created);
 
        // Create reader
-       p->reader = pakfire_make_archive_disk_reader(p->pakfire, 1);
+       p->reader = pakfire_get_disk_reader(p->pakfire);
        if (!p->reader)
                goto ERROR;
 
index d41757d8d44f4026a00a375c8a5050fbb3fe98e5..d517df842a9d511b651c68eb3ff3f3f944c77be9 100644 (file)
@@ -119,6 +119,7 @@ struct pakfire {
        unsigned int in_free:1;
 
        // Disk Reader/Writer
+       struct archive* reader;
        struct archive* writer;
 };
 
@@ -427,6 +428,8 @@ static void pakfire_free(struct pakfire* pakfire) {
 
        if (pakfire->pool)
                pool_free(pakfire->pool);
+       if (pakfire->reader)
+               archive_read_free(pakfire->reader);
        if (pakfire->writer)
                archive_write_free(pakfire->writer);
        if (pakfire->config)
@@ -1593,29 +1596,39 @@ static const char* pakfire_group_lookup(void* data, la_int64_t gid) {
        return entry->gr_name;
 }
 
-struct archive* pakfire_make_archive_disk_reader(struct pakfire* pakfire, int internal) {
-       struct archive* archive = archive_read_disk_new();
-       if (!archive)
-               return NULL;
+struct archive* pakfire_get_disk_reader(struct pakfire* pakfire) {
+       int r;
 
-       // Do not read fflags
-       int r = archive_read_disk_set_behavior(archive, ARCHIVE_READDISK_NO_FFLAGS);
-       if (r) {
-               CTX_ERROR(pakfire->ctx, "Could not change behavior of reader: %s\n",
-                       archive_error_string(archive));
-               archive_read_free(archive);
-               return NULL;
+       if (!pakfire->reader) {
+               // Create a new reader
+               pakfire->reader = archive_read_disk_new();
+               if (!pakfire->reader) {
+                       CTX_ERROR(pakfire->ctx, "Could not set up reader: %m\n");
+                       return NULL;
+               }
+
+               // Do not read fflags
+               r = archive_read_disk_set_behavior(pakfire->reader, ARCHIVE_READDISK_NO_FFLAGS);
+               if (r) {
+                       CTX_ERROR(pakfire->ctx, "Could not change behavior of reader: %s\n",
+                               archive_error_string(pakfire->reader));
+                       goto ERROR;
+               }
+
+               // Install user/group lookups
+               archive_read_disk_set_uname_lookup(pakfire->reader, pakfire, pakfire_user_lookup, NULL);
+               archive_read_disk_set_gname_lookup(pakfire->reader, pakfire, pakfire_group_lookup, NULL);
        }
 
-       // Install user/group lookups
-       if (internal) {
-               archive_read_disk_set_uname_lookup(archive, pakfire, pakfire_user_lookup, NULL);
-               archive_read_disk_set_gname_lookup(archive, pakfire, pakfire_group_lookup, NULL);
-       } else {
-               archive_read_disk_set_standard_lookup(archive);
+       return pakfire->reader;
+
+ERROR:
+       if (pakfire->reader) {
+               archive_read_free(pakfire->reader);
+               pakfire->reader = NULL;
        }
 
-       return archive;
+       return NULL;
 }
 
 static la_int64_t pakfire_uid_lookup(void* data, const char* name, la_int64_t uid) {