]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
util: Improve error reporting for archive copy
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 Aug 2022 10:12:41 +0000 (10:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 Aug 2022 10:12:41 +0000 (10:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/util.h
src/libpakfire/snapshot.c
src/libpakfire/util.c

index 1295b12a0d6c4f2fedf1e6a25b1b5eebba000487..1c8df8d4ddf5ac7cac3de6994786f2f977cf736c 100644 (file)
@@ -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);
 
index 9bf0118c6cb86397cb6f0f2c1d53bf04febef9e5..1a21e1eab6d2ad56766d34bd69c27f519175c577 100644 (file)
@@ -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;
                        }
                }
index ecbc531e8607f84cb791a1b74328e05563136514..fe4bd69c20885a72ab19675e772053991f8915c9 100644 (file)
@@ -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;
+               }
        }
 }