#include <archive.h>
#include <archive_entry.h>
+#include <pakfire/archive.h>
#include <pakfire/constants.h>
#include <pakfire/logging.h>
#include <pakfire/package.h>
archive_entry_set_perm(entry, 0644);
// Set length
- archive_entry_set_size(entry, strlen(buffer));
+ archive_entry_set_size(entry, strlen(buffer));
// This is the end of the header
int r = archive_write_header(a, entry);
return 0;
}
+static int pakfire_packager_write_payload(struct pakfire_packager* packager,
+ struct archive* a) {
+ struct stat st;
+
+ // Close the payload
+ if (packager->payload) {
+ archive_write_free(packager->payload);
+ packager->payload = NULL;
+ }
+
+ // Reset fd to beginning of the file
+ rewind(packager->fpayload);
+
+ int fd = fileno(packager->fpayload);
+
+ // Stat the payload file
+ int r = fstat(fd, &st);
+ if (r) {
+ ERROR(packager->pakfire, "stat() on fd %d failed: %s\n", fd, strerror(errno));
+ return 1;
+ }
+
+ // Create a new file entry
+ struct archive_entry* entry = archive_entry_new();
+ if (!entry)
+ return 1;
+
+ // Set filename
+ archive_entry_set_pathname(entry, PAKFIRE_ARCHIVE_FN_PAYLOAD);
+
+ // This is a regular file
+ archive_entry_set_filetype(entry, AE_IFREG);
+ archive_entry_set_perm(entry, 0644);
+
+ // Set the file size
+ archive_entry_set_size(entry, st.st_size);
+
+ // This is the end of the header
+ r = archive_write_header(a, entry);
+ if (r) {
+ ERROR(packager->pakfire, "Error writing header: %s\n", archive_error_string(a));
+ goto ERROR;
+ }
+
+ // Copy data
+ r = pakfire_packager_copy_data(packager, a, packager->fpayload);
+ if (r)
+ goto ERROR;
+
+ // Success
+ r = 0;
+
+ERROR:
+ archive_entry_free(entry);
+
+ return r;
+}
+
/*
This function is being called at the end when all data has been added to the package.
if (r)
goto ERROR;
+ // Write the payload
+ r = pakfire_packager_write_payload(packager, a);
+ if (r)
+ goto ERROR;
+
// XXX set filename
ERROR: