return r;
}
+
+int pakfire_compress_create_archive(struct pakfire* pakfire, struct archive** archive,
+ FILE* f, const enum pakfire_compressions compression, const unsigned int level) {
+ struct archive* a = NULL;
+ char value[16];
+ int r;
+
+ // Open a new archive
+ a = archive_write_new();
+ if (!a) {
+ ERROR(pakfire, "archive_write_new() failed\n");
+ r = 1;
+ goto ERROR;
+ }
+
+ // Use the PAX format
+ r = archive_write_set_format_pax(a);
+ if (r) {
+ ERROR(pakfire, "Could not set format to PAX: %s\n", archive_error_string(a));
+ goto ERROR;
+ }
+
+ // Store any extended attributes in the SCHILY headers
+ r = archive_write_set_format_option(a, "pax", "xattrheader", "SCHILY");
+ if (r) {
+ ERROR(pakfire, "Could not set xattrheader option: %s\n", archive_error_string(a));
+ goto ERROR;
+ }
+
+ switch (compression) {
+ case PAKFIRE_COMPRESS_ZSTD:
+ // Enable Zstd
+ r = archive_write_add_filter_zstd(a);
+ if (r) {
+ ERROR(pakfire, "Could not enable Zstandard compression: %s\n",
+ archive_error_string(a));
+ goto ERROR;
+ }
+
+ // Do not pad the last block
+ archive_write_set_bytes_in_last_block(a, 1);
+
+ // Set compression level
+ if (level) {
+ r = pakfire_string_format(value, "%u", level);
+ if (r)
+ goto ERROR;
+
+ r = archive_write_set_filter_option(a, NULL, "compression-level", value);
+ if (r) {
+ ERROR(pakfire, "Could not set Zstandard compression level: %s\n",
+ archive_error_string(a));
+ goto ERROR;
+ }
+ }
+ }
+
+ // Write archive to f
+ if (f) {
+ r = archive_write_open_FILE(a, f);
+ if (r) {
+ ERROR(pakfire, "archive_write_open_FILE() failed: %s\n", archive_error_string(a));
+ goto ERROR;
+ }
+ }
+
+ // Success
+ *archive = a;
+
+ return 0;
+
+ERROR:
+ if (a)
+ archive_write_free(a);
+
+ return r;
+}
const char* message, pakfire_walk_filter_callback filter_callback,
int flags);
+// Algorithms
+enum pakfire_compressions {
+ PAKFIRE_COMPRESS_ZSTD,
+};
+
// Compress
enum pakfire_compress_flags {
PAKFIRE_COMPRESS_NO_PROGRESS = (1 << 1),
int pakfire_compress(struct pakfire* pakfire, struct archive* archive,
struct pakfire_filelist* filelist, const char* message, int flags, int digests);
+int pakfire_compress_create_archive(struct pakfire* pakfire, struct archive** archive,
+ FILE* f, const enum pakfire_compressions compression, const unsigned int level);
+
#endif
#endif /* PAKFIRE_COMPRESS_H */
*/
int pakfire_packager_finish(struct pakfire_packager* packager, FILE* f) {
struct archive* a = NULL;
- const char* comp_level = NULL;
+ unsigned int level = -1;
int r = 1;
const char* nevra = pakfire_package_get_string(packager->pkg, PAKFIRE_PKG_NEVRA);
if (r)
goto ERROR;
- // Open a new archive
- a = archive_write_new();
- if (!a) {
- ERROR(packager->pakfire, "archive_write_new() failed\n");
- r = 1;
- goto ERROR;
- }
-
- // Use the PAX format
- 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;
- }
-
- // Store any extended attributes in the SCHILY headers
- r = archive_write_set_format_option(a, "pax", "xattrheader", "SCHILY");
- if (r) {
- ERROR(packager->pakfire, "Could not set xattrheader option: %s\n",
- archive_error_string(a));
- return r;
- }
-
- // Enable Zstd
- r = archive_write_add_filter_zstd(a);
- if (r) {
- ERROR(packager->pakfire, "Could not enable Zstandard compression: %s\n",
- archive_error_string(a));
- return r;
- }
-
// Select compression level
if (pakfire_package_is_source(packager->pkg))
- comp_level = "1";
+ level = 1;
else
- comp_level = "22";
+ level = 22;
- // Set compression level to highest
- r = archive_write_set_filter_option(a, NULL, "compression-level", comp_level);
- if (r) {
- ERROR(packager->pakfire, "Could not set Zstandard compression level: %s\n",
- archive_error_string(a));
- return r;
- }
+ // Create a new archive that is being compressed as fast as possible
+ r = pakfire_compress_create_archive(packager->pakfire, &a, f,
+ PAKFIRE_COMPRESS_ZSTD, level);
+ if (r)
+ goto ERROR;
// Add feature marker
pakfire_package_add_dep(packager->pkg,
PAKFIRE_PKG_REQUIRES, "pakfire(Compress-Zstandard)");
- // Do not pad the last block
- archive_write_set_bytes_in_last_block(a, 1);
-
- // 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) {
return r;
}
-static struct archive* pakfire_snapshot_create_archive(struct pakfire* pakfire, FILE* f) {
- struct archive* a = archive_write_new();
- if (!a) {
- ERROR(pakfire, "archive_write_new() failed\n");
- return NULL;
- }
-
- // Use the PAX format
- int r = archive_write_set_format_pax(a);
- if (r) {
- ERROR(pakfire, "Could not set format to PAX: %s\n", archive_error_string(a));
- goto ERROR;
- }
-
- // Enable Zstd
- r = archive_write_add_filter_zstd(a);
- if (r) {
- ERROR(pakfire, "Could not enable Zstandard compression: %s\n",
- archive_error_string(a));
- goto ERROR;
- }
-
- // Set compression level to fastest
- r = archive_write_set_filter_option(a, NULL, "compression-level", "1");
- if (r) {
- ERROR(pakfire, "Could not set Zstandard compression level: %s\n",
- archive_error_string(a));
- goto ERROR;
- }
-
- // Do not pad the last block
- archive_write_set_bytes_in_last_block(a, 1);
-
- // Write archive to file
- r = archive_write_open_FILE(a, f);
- if (r)
- goto ERROR;
-
- return a;
-
-ERROR:
- archive_write_free(a);
-
- return NULL;
-}
-
int pakfire_snapshot_compress(struct pakfire* pakfire, FILE* f) {
struct pakfire_filelist* filelist = NULL;
struct archive* archive = NULL;
goto ERROR;
}
- // Create a new archive
- archive = pakfire_snapshot_create_archive(pakfire, f);
- if (!archive) {
- ERROR(pakfire, "Could not open archive for writing\n");
+ // Create a new archive that is being compressed as fast as possible
+ r = pakfire_compress_create_archive(pakfire, &archive, f, PAKFIRE_COMPRESS_ZSTD, 1);
+ if (r)
goto ERROR;
- }
// Write the payload to the archive
r = pakfire_compress(pakfire, archive, filelist, _("Storing Snapshot"),