]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Fix return code of pakfire_copy on error
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 13:16:00 +0000 (13:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 13:16:00 +0000 (13:16 +0000)
Before, the function count return zero even though an error occured.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 345be179eaf14027e2bfcc00a80c0b672e744505..39c94a96f9eabcb9cfba9d08aaa3f50fb39fb980 100644 (file)
@@ -1011,6 +1011,8 @@ static int pakfire_copy(struct pakfire* pakfire, const char* src, const char* ds
        FILE* f = NULL;
        int r = 1;
 
+       DEBUG(pakfire, "Copying %s to %s\n", src, dst);
+
        // Allocate reader
        reader = archive_read_disk_new();
        if (!reader)
@@ -1049,8 +1051,10 @@ static int pakfire_copy(struct pakfire* pakfire, const char* src, const char* ds
        // Copy payload
        if (archive_entry_filetype(entry) == AE_IFREG) {
                f = fopen(src, "r");
-               if (!f)
+               if (!f) {
+                       r = 1;
                        goto ERROR;
+               }
 
                while (!feof(f)) {
                        size_t bytes_read = fread(buffer, 1, sizeof(buffer), f);
@@ -1058,12 +1062,14 @@ static int pakfire_copy(struct pakfire* pakfire, const char* src, const char* ds
                        // Check if any error occured
                        if (ferror(f)) {
                                ERROR(pakfire, "Error reading from file: %m\n");
+                               r = 1;
                                goto ERROR;
                        }
 
                        ssize_t bytes_written = archive_write_data(writer, buffer, bytes_read);
                        if (bytes_written < 0) {
                                ERROR(pakfire, "Error writing data: %s\n", archive_error_string(writer));
+                               r = 1;
                                goto ERROR;
                        }
                }