diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-08-10 17:46:49 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-08-14 15:09:11 +0200 |
commit | 65886ff172190648c1114a9953c154f3f4821119 (patch) | |
tree | 17bd97db9fd30d58d8ea5864f66734dae98510a7 | |
parent | 149b74e00eb0937231087251d7644be0aa478929 (diff) | |
download | justbuild-65886ff172190648c1114a9953c154f3f4821119.tar.gz |
ArchiveOps: Add handling of 7zip archives
Also updates the archive usage tests accordingly.
-rw-r--r-- | src/other_tools/utils/archive_ops.cpp | 14 | ||||
-rw-r--r-- | src/other_tools/utils/archive_ops.hpp | 3 | ||||
-rw-r--r-- | test/other_tools/utils/archive_usage.test.cpp | 15 |
3 files changed, 29 insertions, 3 deletions
diff --git a/src/other_tools/utils/archive_ops.cpp b/src/other_tools/utils/archive_ops.cpp index dd291036..a0804abc 100644 --- a/src/other_tools/utils/archive_ops.cpp +++ b/src/other_tools/utils/archive_ops.cpp @@ -71,7 +71,7 @@ auto enable_write_filter(archive* aw, ArchiveType type) -> bool { auto enable_read_filter(archive* ar, ArchiveType type) -> bool { switch (type) { case ArchiveType::Tar: - return true; // no compression filter + return true; // no outside compression filter case ArchiveType::TarGz: return (archive_read_support_filter_gzip(ar) == ARCHIVE_OK); case ArchiveType::TarBz2: @@ -142,6 +142,12 @@ auto ArchiveOps::EnableWriteFormats(archive* aw, ArchiveType type) std::string(archive_error_string(aw)); } } break; + case ArchiveType::_7Zip: { + if (archive_write_set_format_7zip(aw) != ARCHIVE_OK) { + return std::string("ArchiveOps: ") + + std::string(archive_error_string(aw)); + } + } break; case ArchiveType::Tar: case ArchiveType::TarGz: case ArchiveType::TarBz2: @@ -170,6 +176,12 @@ auto ArchiveOps::EnableReadFormats(archive* ar, ArchiveType type) std::string(archive_error_string(ar)); } } break; + case ArchiveType::_7Zip: { + if (archive_read_support_format_7zip(ar) != ARCHIVE_OK) { + return std::string("ArchiveOps: ") + + std::string(archive_error_string(ar)); + } + } break; case ArchiveType::TarAuto: case ArchiveType::Tar: case ArchiveType::TarGz: diff --git a/src/other_tools/utils/archive_ops.hpp b/src/other_tools/utils/archive_ops.hpp index 91595867..94013f30 100644 --- a/src/other_tools/utils/archive_ops.hpp +++ b/src/other_tools/utils/archive_ops.hpp @@ -27,13 +27,14 @@ using archive_entry = struct archive_entry; enum class ArchiveType : size_t { Zip, + _7Zip, Tar, // uncompressed TarGz, TarBz2, TarXz, TarLz, TarLzma, - TarAuto, // autodetect tarball-type archives + TarAuto // autodetect tarball-type archives }; /// \brief Class handling archiving and unarchiving operations via libarchive diff --git a/test/other_tools/utils/archive_usage.test.cpp b/test/other_tools/utils/archive_usage.test.cpp index 3131e7a2..542f05e1 100644 --- a/test/other_tools/utils/archive_usage.test.cpp +++ b/test/other_tools/utils/archive_usage.test.cpp @@ -90,7 +90,13 @@ std::vector<archive_test_info_t> const kTestScenarios = { .test_dir = "test_zip", .filename = "test.zip", .tools = {"unzip"}, - .cmd = "/usr/bin/unzip"}}; + .cmd = "/usr/bin/unzip"}, + {.test_name = "7zip", + .type = ArchiveType::_7Zip, + .test_dir = "test_7zip", + .filename = "test.7z", + .tools = {"7z"}, // 7z comes with its own lzma-type compression + .cmd = "/usr/bin/7z x"}}; [[nodiscard]] auto read_archive(archive* a, std::string const& path) -> filetree_t { @@ -147,6 +153,7 @@ void extract_archive(std::string const& path) { REQUIRE(a != nullptr); REQUIRE(archive_read_support_format_tar(a) == ARCHIVE_OK); REQUIRE(archive_read_support_format_zip(a) == ARCHIVE_OK); + REQUIRE(archive_read_support_format_7zip(a) == ARCHIVE_OK); REQUIRE(archive_read_support_filter_gzip(a) == ARCHIVE_OK); REQUIRE(archive_read_support_filter_bzip2(a) == ARCHIVE_OK); REQUIRE(archive_read_support_filter_xz(a) == ARCHIVE_OK); @@ -223,6 +230,9 @@ void enable_write_format_and_filter(archive* aw, ArchiveType type) { case ArchiveType::Zip: { REQUIRE(archive_write_set_format_zip(aw) == ARCHIVE_OK); } break; + case ArchiveType::_7Zip: { + REQUIRE(archive_write_set_format_7zip(aw) == ARCHIVE_OK); + } break; case ArchiveType::Tar: { REQUIRE(archive_write_set_format_pax_restricted(aw) == ARCHIVE_OK); } break; @@ -256,6 +266,9 @@ void enable_read_format_and_filter(archive* ar, ArchiveType type) { case ArchiveType::Zip: { REQUIRE(archive_read_support_format_zip(ar) == ARCHIVE_OK); } break; + case ArchiveType::_7Zip: { + REQUIRE(archive_read_support_format_7zip(ar) == ARCHIVE_OK); + } break; case ArchiveType::Tar: { REQUIRE(archive_read_support_format_tar(ar) == ARCHIVE_OK); } break; |