]> git.ipfire.org Git - pakfire.git/commitdiff
util: Terminate pakfire_copy() even if feof() does not work
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 31 Dec 2024 18:19:21 +0000 (18:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 31 Dec 2024 18:19:21 +0000 (18:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/util.c

index 7af040c64f71863b367ec8f030b56efdd93329fb..f461b4b37229284bd7830ad233fdee88b2506a49 100644 (file)
@@ -618,14 +618,18 @@ int pakfire_copy(struct pakfire_ctx* ctx, FILE* src, FILE* dst) {
                // Check for any errors
                if (ferror(src)) {
                        ERROR(ctx, "Could not read data: %m\n");
-                       return 1;
+                       return -errno;
                }
 
+               // Break if we could not read anything
+               if (!bytes_read)
+                       break;
+
                // Write the data
                bytes_written = fwrite(buffer, 1, bytes_read, dst);
                if (bytes_written < bytes_read) {
                        ERROR(ctx, "Could not write data: %m\n");
-                       return 1;
+                       return -errno;
                }
        }