#ifndef PAKFIRE_CONSTANTS_H
#define PAKFIRE_CONSTANTS_H
+#define _TO_STRING(x) #x
+#define TO_STRING(x) _TO_STRING(x)
+
#define STRING_SIZE 1024
#define PAKFIRE_REPO_SYSTEM_NAME "@system"
#define PAKFIRE_MACROS_DIR "/usr/lib/pakfire/macros"
#define PAKFIRE_MACROS_GLOB_PATTERN PAKFIRE_MACROS_DIR "/*.macro"
+#ifdef PAKFIRE_PRIVATE
+
+// The file format that this version generates
+#define PACKAGE_FORMAT 5
+
+#endif /* PAKFIRE_PRIVATE */
+
#endif /* PAKFIRE_CONSTANTS_H */
#include <archive.h>
#include <archive_entry.h>
+#include <pakfire/constants.h>
#include <pakfire/logging.h>
#include <pakfire/package.h>
#include <pakfire/packager.h>
return NULL;
}
+static int pakfire_packager_write_format(struct pakfire_packager* packager,
+ struct archive* a) {
+ const char buffer[] = TO_STRING(PACKAGE_FORMAT) "\n";
+
+ // Create a new file entry
+ struct archive_entry* entry = archive_entry_new();
+ if (!entry)
+ return 1;
+
+ // Set filename
+ archive_entry_set_pathname(entry, "pakfire-format");
+
+ // This is a regular file
+ archive_entry_set_filetype(entry, AE_IFREG);
+ archive_entry_set_perm(entry, 0644);
+
+ // Set length
+ archive_entry_set_size(entry, strlen(buffer));
+
+ // This is the end of the header
+ int r = archive_write_header(a, entry);
+ if (r) {
+ ERROR(packager->pakfire, "Error writing header: %s\n", archive_error_string(a));
+ archive_entry_free(entry);
+ return r;
+ }
+
+ // Write content
+ r = archive_write_data(a, buffer, strlen(buffer));
+ if (r < 0) {
+ ERROR(packager->pakfire, "Error writing data: %s\n", archive_error_string(a));
+ archive_entry_free(entry);
+ return r;
+ }
+
+ archive_entry_free(entry);
+
+ return 0;
+}
+
+/*
+ This function is being called at the end when all data has been added to the package.
+
+ It will create a new archive and write the package to the given file descriptor.
+*/
+PAKFIRE_EXPORT char* pakfire_packager_finish(struct pakfire_packager* packager, FILE* f) {
+ char* filename = NULL;
+
+ // Open a new archive
+ struct archive* a = archive_write_new();
+ if (!a) {
+ ERROR(packager->pakfire, "archive_write_new() failed\n");
+ goto ERROR;
+ }
+
+ // Use the PAX format
+ int r = archive_write_set_format_pax(a);
+ if (r) {
+ ERROR(packager->pakfire, "Could not set format to PAX: %s\n",
+ archive_error_string(a));
+ goto ERROR;
+ }
+
+ // Write archive to f
+ r = archive_write_open_FILE(a, f);
+ if (r) {
+ ERROR(packager->pakfire, "archive_write_open_FILE() failed: %s\n",
+ archive_error_string(a));
+ goto ERROR;
+ }
+
+ // Start with the format file
+ r = pakfire_packager_write_format(packager, a);
+ if (r)
+ goto ERROR;
+
+ // XXX set filename
+
+ERROR:
+ if (a)
+ archive_free(a);
+
+ return filename;
+}
+
PAKFIRE_EXPORT int pakfire_packager_add(struct pakfire_packager* packager,
const char* path) {
FILE* f = NULL;