#include <string.h>
#include <sys/queue.h>
#include <sys/types.h>
+#include <sys/sendfile.h>
#include <sys/stat.h>
// libarchive
return r;
}
+int pakfire_archive_copy(struct pakfire_archive* archive, const char* path) {
+ if (!path) {
+ errno = EINVAL;
+ return 1;
+ }
+
+ // Determine the file size
+ ssize_t size = pakfire_archive_get_size(archive);
+ if (size < 0)
+ return 1;
+
+ DEBUG(archive->pakfire, "Copying %s to %s...\n", archive->path, path);
+
+ // Open destination file
+ FILE* f = fopen(path, "w");
+ if (!f)
+ return 1;
+
+ int r = 1;
+
+ // Copy everything
+ ssize_t bytes_written = sendfile(fileno(f), fileno(archive->f), NULL, size);
+ if (bytes_written != size)
+ goto ERROR;
+
+ // Success
+ r = 0;
+
+ERROR:
+ fclose(f);
+
+ // Delete the file on error
+ if (r)
+ unlink(path);
+
+ rewind(archive->f);
+
+ return r;
+}
+
static int pakfire_archive_extraction_path(struct pakfire_archive* archive,
char* path, size_t length, const char* prefix) {
char buffer[PATH_MAX];
#ifdef PAKFIRE_PRIVATE
+int pakfire_archive_copy(struct pakfire_archive* archive, const char* path);
+
struct pakfire_scriptlet* pakfire_archive_get_scriptlet(
struct pakfire_archive* archive, const char* type);