From: Michael Tremer Date: Mon, 21 Oct 2024 14:43:10 +0000 (+0000) Subject: archive: Fetch the writer only once X-Git-Tag: 0.9.30~977 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f777496e6e4055ede351434c38499af15c4df1a0;p=pakfire.git archive: Fetch the writer only once Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index 4db24b368..5b5b03415 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -994,8 +994,8 @@ struct pakfire_extract_state { // Prefix const char* prefix; - // Flags - int flags; + // Writer + struct archive* writer; }; static void pakfire_extract_progress(void* data) { @@ -1093,49 +1093,46 @@ static int pakfire_archive_extract_one(struct pakfire_ctx* ctx, } } - // We are done if we are running in dry-run mode - if (state->flags & PAKFIRE_EXTRACT_DRY_RUN) - goto ERROR; - - struct archive* writer = pakfire_get_disk_writer(archive->pakfire); - - // Fetch path again since we changed it - path = archive_entry_pathname(entry); + // Write the file... + if (state->writer) { + // Fetch path again since we changed it + path = archive_entry_pathname(entry); - CTX_DEBUG(ctx, "Extracting %s\n", path); + CTX_DEBUG(ctx, "Extracting %s\n", path); - // Remove any extended attributes which we never write to disk - archive_entry_xattr_clear(entry); + // Remove any extended attributes which we never write to disk + archive_entry_xattr_clear(entry); - // Set capabilities - if (pakfire_file_has_caps(file)) { - r = pakfire_file_write_fcaps(file, &cap_data); - if (r) - goto ERROR; + // Set capabilities + if (pakfire_file_has_caps(file)) { + r = pakfire_file_write_fcaps(file, &cap_data); + if (r) + goto ERROR; - // Store capabilities in archive entry - archive_entry_xattr_add_entry(entry, - "security.capability", &cap_data, sizeof(cap_data)); - } + // Store capabilities in archive entry + archive_entry_xattr_add_entry(entry, + "security.capability", &cap_data, sizeof(cap_data)); + } - // Write payload - r = archive_read_extract2(state->a, entry, writer); - switch (r) { - case ARCHIVE_OK: - r = 0; - break; + // Write payload + r = archive_read_extract2(state->a, entry, state->writer); + switch (r) { + case ARCHIVE_OK: + r = 0; + break; - case ARCHIVE_WARN: - CTX_ERROR(ctx, "%s\n", archive_error_string(writer)); + case ARCHIVE_WARN: + CTX_ERROR(ctx, "%s\n", archive_error_string(state->writer)); - // Pretend everything has been okay - r = 0; - break; + // Pretend everything has been okay + r = 0; + break; - case ARCHIVE_FATAL: - CTX_ERROR(ctx, "%s\n", archive_error_string(writer)); - r = 1; - break; + case ARCHIVE_FATAL: + CTX_ERROR(ctx, "%s\n", archive_error_string(state->writer)); + r = 1; + break; + } } ERROR: @@ -1148,6 +1145,7 @@ ERROR: static int __pakfire_archive_extract(struct pakfire_archive* archive, const char* path, int flags) { struct pakfire_package* pkg = NULL; char prefix[PATH_MAX] = "/"; + struct archive* writer = NULL; struct archive* a = NULL; int r; @@ -1177,6 +1175,15 @@ static int __pakfire_archive_extract(struct pakfire_archive* archive, const char goto ERROR; } + // Setup the writer if we are not running in dry mode + if (!(flags & PAKFIRE_EXTRACT_DRY_RUN)) { + writer = pakfire_get_disk_writer(archive->pakfire); + if (!writer) { + r = -errno; + goto ERROR; + } + } + // Fetch NEVRA const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); @@ -1221,7 +1228,7 @@ static int __pakfire_archive_extract(struct pakfire_archive* archive, const char .archive = archive, .a = a, .prefix = prefix, - .flags = flags, + .writer = writer, }; // Register progress callback