diff --git a/include/system.hpp b/include/system.hpp index 8777e002..115ac4dd 100644 --- a/include/system.hpp +++ b/include/system.hpp @@ -111,7 +111,7 @@ An equivalent shell command is tar -cf archivePath --zstd -C folderPath . */ -void archiveFolder(const std::string& archivePath, const std::string& folderPath); +void archiveFolder(const std::string& archivePath, const std::string& folderPath, int compressionLevel = 1); /** Extracts an archive into a folder. An equivalent shell command is diff --git a/src/patch.cpp b/src/patch.cpp index 613f0c15..de808743 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -63,7 +63,8 @@ void PatchManager::save(std::string path) { saveAutosave(); uint64_t startTime = system::getNanoseconds(); - system::archiveFolder(path, asset::autosavePath); + // Set compression level to 1 so that a 500MB/s SSD is almost bottlenecked + system::archiveFolder(path, asset::autosavePath, 1); uint64_t endTime = system::getNanoseconds(); INFO("Archived patch in %lf seconds", (endTime - startTime) / 1e9); } diff --git a/src/system.cpp b/src/system.cpp index a1766e2c..0cfecec3 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -288,7 +288,7 @@ static std::string getRelativePath(std::string path, std::string base) { } -void archiveFolder(const std::string& archivePath, const std::string& folderPath) { +void archiveFolder(const std::string& archivePath, const std::string& folderPath, int compressionLevel) { // Based on minitar.c create() in libarchive examples int r; @@ -297,8 +297,8 @@ void archiveFolder(const std::string& archivePath, const std::string& folderPath DEFER({archive_write_free(a);}); archive_write_set_format_ustar(a); archive_write_add_filter_zstd(a); - // Set compression level roughly so that a 500MB/s SSD is bottlenecked - r = archive_write_set_filter_option(a, NULL, "compression-level", "1"); + assert(0 <= compressionLevel && compressionLevel <= 19); + r = archive_write_set_filter_option(a, NULL, "compression-level", std::to_string(compressionLevel).c_str()); if (r < ARCHIVE_OK) throw Exception(string::f("archiveFolder() could not set filter option: %s", archive_error_string(a)));