]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Rewind before copy
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Sep 2022 14:39:06 +0000 (14:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Sep 2022 14:39:06 +0000 (14:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c

index ffca5304f6f733373cebd60456fba515551b15ae..61c92b3534a6150d83639fd78aa95b2148883237 100644 (file)
@@ -823,6 +823,9 @@ int pakfire_archive_copy(struct pakfire_archive* archive, const char* path) {
 
        DEBUG(archive->pakfire, "Copying %s to %s...\n", archive->path, path);
 
+       // Ensure we copy from the very beginning
+       rewind(archive->f);
+
        // Open destination file
        FILE* f = fopen(path, "w");
        if (!f)
@@ -832,8 +835,11 @@ int pakfire_archive_copy(struct pakfire_archive* archive, const char* path) {
 
        // Copy everything
        ssize_t bytes_written = sendfile(fileno(f), fileno(archive->f), NULL, size);
-       if (bytes_written != size)
+       if (bytes_written < size) {
+               ERROR(archive->pakfire, "Could not copy archive (%zu byte(s) written): %m\n",
+                       bytes_written);
                goto ERROR;
+       }
 
        // Success
        r = 0;
@@ -845,8 +851,6 @@ ERROR:
        if (r)
                unlink(path);
 
-       rewind(archive->f);
-
        return r;
 }