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)
// 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;
if (r)
unlink(path);
- rewind(archive->f);
-
return r;
}