From 17a9f2d54a487fc5262efb8a2787b0fbeca368b1 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 12 Aug 2022 10:12:41 +0000 Subject: [PATCH] util: Improve error reporting for archive copy Signed-off-by: Michael Tremer --- src/libpakfire/include/pakfire/util.h | 3 ++- src/libpakfire/snapshot.c | 11 +---------- src/libpakfire/util.c | 22 ++++++++++++++++------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 1295b12a..1c8df8d4 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -100,7 +100,8 @@ size_t pakfire_digest_length(enum pakfire_digests digest); // Archive Stuff -int pakfire_archive_copy_data(struct archive* src, struct archive* dst); +int pakfire_archive_copy_data(struct pakfire* pakfire, + struct archive* src, struct archive* dst); int pakfire_archive_copy_data_to_buffer(struct pakfire* pakfire, struct archive* a, struct archive_entry* entry, char** data, size_t* data_size); diff --git a/src/libpakfire/snapshot.c b/src/libpakfire/snapshot.c index 9bf0118c..1a21e1ea 100644 --- a/src/libpakfire/snapshot.c +++ b/src/libpakfire/snapshot.c @@ -185,18 +185,9 @@ int pakfire_snapshot_create(struct pakfire* pakfire, FILE* f) { // Copy payload if (archive_entry_filetype(entry) == AE_IFREG) { - r = pakfire_archive_copy_data(reader, a); + r = pakfire_archive_copy_data(pakfire, reader, a); if (r) { ERROR(pakfire, "Could not copy %s\n", archive_entry_pathname(entry)); - - const char* error = archive_error_string(reader); - if (error) - ERROR(pakfire, "Read error: %s\n", error); - - error = archive_error_string(a); - if (error) - ERROR(pakfire, "Write error: %s\n", error); - goto ERROR; } } diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index ecbc531e..fe4bd69c 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -1050,24 +1050,34 @@ size_t pakfire_digest_length(enum pakfire_digests digest) { // Archive Stuff -int pakfire_archive_copy_data(struct archive* src, struct archive* dst) { - const void* buffer; - size_t size; - off_t offset; +int pakfire_archive_copy_data(struct pakfire* pakfire, + struct archive* src, struct archive* dst) { + const void* buffer = NULL; + size_t size = 0; + off_t offset = 0; + int r; for (;;) { // Read a block of data r = archive_read_data_block(src, &buffer, &size, &offset); + + // Exit if we have read everything from source if (r == ARCHIVE_EOF) return ARCHIVE_OK; - else if (r) + + // Catch any reading errors + else if (r) { + ERROR(pakfire, "Read error: %s\n", archive_error_string(src)); return r; + } // Write the read block of data r = archive_write_data(dst, buffer, size); - if (r < 0) + if (r < 0) { + ERROR(pakfire, "Write error: %s\n", archive_error_string(dst)); return r; + } } } -- 2.47.3