From: Michael Tremer Date: Sun, 7 Mar 2021 17:06:32 +0000 (+0000) Subject: packager: Append payload to archive X-Git-Tag: 0.9.28~1285^2~616 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2adc4a4a70268aebbabca6c0359181282060cc1c;p=pakfire.git packager: Append payload to archive Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/packager.c b/src/libpakfire/packager.c index e7e32fbe4..ddbfe9f84 100644 --- a/src/libpakfire/packager.c +++ b/src/libpakfire/packager.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -209,7 +210,7 @@ static int pakfire_packager_write_format(struct pakfire_packager* packager, 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); @@ -232,6 +233,64 @@ static int pakfire_packager_write_format(struct pakfire_packager* packager, 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. @@ -268,6 +327,11 @@ PAKFIRE_EXPORT char* pakfire_packager_finish(struct pakfire_packager* packager, if (r) goto ERROR; + // Write the payload + r = pakfire_packager_write_payload(packager, a); + if (r) + goto ERROR; + // XXX set filename ERROR: