From: Michael Tremer Date: Tue, 22 Oct 2024 01:44:39 +0000 (+0000) Subject: pakfire: Align the disk reader with the writer X-Git-Tag: 0.9.30~961 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ea668919efb54e4d91a852e449d7232f10fc6e0f;p=pakfire.git pakfire: Align the disk reader with the writer Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/filelist.c b/src/libpakfire/filelist.c index 5d8194a0a..be59048fd 100644 --- a/src/libpakfire/filelist.c +++ b/src/libpakfire/filelist.c @@ -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; } diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index ecceb1764..02bf2755e 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -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 diff --git a/src/libpakfire/packager.c b/src/libpakfire/packager.c index 69ada5801..0a91d8944 100644 --- a/src/libpakfire/packager.c +++ b/src/libpakfire/packager.c @@ -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; diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index d41757d8d..d517df842 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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) {