Browse Source

Add `compressionLevel` argument to `system::archiveFolder()`.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
232d2c10e5
3 changed files with 6 additions and 5 deletions
  1. +1
    -1
      include/system.hpp
  2. +2
    -1
      src/patch.cpp
  3. +3
    -3
      src/system.cpp

+ 1
- 1
include/system.hpp View File

@@ -111,7 +111,7 @@ An equivalent shell command is


tar -cf archivePath --zstd -C folderPath . 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. /** Extracts an archive into a folder.
An equivalent shell command is An equivalent shell command is




+ 2
- 1
src/patch.cpp View File

@@ -63,7 +63,8 @@ void PatchManager::save(std::string path) {
saveAutosave(); saveAutosave();


uint64_t startTime = system::getNanoseconds(); 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(); uint64_t endTime = system::getNanoseconds();
INFO("Archived patch in %lf seconds", (endTime - startTime) / 1e9); INFO("Archived patch in %lf seconds", (endTime - startTime) / 1e9);
} }


+ 3
- 3
src/system.cpp View File

@@ -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 // Based on minitar.c create() in libarchive examples
int r; int r;


@@ -297,8 +297,8 @@ void archiveFolder(const std::string& archivePath, const std::string& folderPath
DEFER({archive_write_free(a);}); DEFER({archive_write_free(a);});
archive_write_set_format_ustar(a); archive_write_set_format_ustar(a);
archive_write_add_filter_zstd(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) if (r < ARCHIVE_OK)
throw Exception(string::f("archiveFolder() could not set filter option: %s", archive_error_string(a))); throw Exception(string::f("archiveFolder() could not set filter option: %s", archive_error_string(a)));




Loading…
Cancel
Save