diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-08-14 10:00:29 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-08-14 15:09:11 +0200 |
commit | 24ad2ce7d070ae684159b6445981017dd7a40f8a (patch) | |
tree | 4eeea470fda336146fdbb92b993a6b0da84d734c /src | |
parent | 26fe1ac82a8437b292e5c17e791c02d5a6813a26 (diff) | |
download | justbuild-24ad2ce7d070ae684159b6445981017dd7a40f8a.tar.gz |
ArchiveOps: Add proper autodetection option for tarballs
We shouldn't exclude the possibility of receiving uncompressed
tarballs as repositories in just-mr. Therefore, we introduce an
explicit type that performs the autodetection (default behaviour
in just-mr). This is done to also be more in line with our
implementation which allows the granular handling of various
archive types (currently used only for testing purposes).
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/root_maps/content_git_map.cpp | 3 | ||||
-rw-r--r-- | src/other_tools/utils/archive_ops.cpp | 12 | ||||
-rw-r--r-- | src/other_tools/utils/archive_ops.hpp | 9 |
3 files changed, 18 insertions, 6 deletions
diff --git a/src/other_tools/root_maps/content_git_map.cpp b/src/other_tools/root_maps/content_git_map.cpp index 7f0b30e0..5fb1bd88 100644 --- a/src/other_tools/root_maps/content_git_map.cpp +++ b/src/other_tools/root_maps/content_git_map.cpp @@ -31,7 +31,8 @@ namespace { std::filesystem::path const& dst_dir) noexcept -> std::optional<std::string> { if (repo_type == "archive") { - return ArchiveOps::ExtractArchive(ArchiveType::Tar, archive, dst_dir); + return ArchiveOps::ExtractArchive( + ArchiveType::TarAuto, archive, dst_dir); } if (repo_type == "zip") { return ArchiveOps::ExtractArchive(ArchiveType::Zip, archive, dst_dir); diff --git a/src/other_tools/utils/archive_ops.cpp b/src/other_tools/utils/archive_ops.cpp index 94c000c7..7115680f 100644 --- a/src/other_tools/utils/archive_ops.cpp +++ b/src/other_tools/utils/archive_ops.cpp @@ -66,16 +66,16 @@ auto enable_write_filter(archive* aw, ArchiveType type) -> bool { auto enable_read_filter(archive* ar, ArchiveType type) -> bool { switch (type) { - case ArchiveType::Tar: // autodetect from supported compression filters - return (archive_read_support_filter_xz(ar) == ARCHIVE_OK) and - (archive_read_support_filter_gzip(ar) == ARCHIVE_OK) and - (archive_read_support_filter_bzip2(ar) == ARCHIVE_OK); + case ArchiveType::Tar: + return true; // no compression filter case ArchiveType::TarGz: return (archive_read_support_filter_gzip(ar) == ARCHIVE_OK); case ArchiveType::TarBz2: return (archive_read_support_filter_bzip2(ar) == ARCHIVE_OK); case ArchiveType::TarXz: return (archive_read_support_filter_xz(ar) == ARCHIVE_OK); + case ArchiveType::TarAuto: + return (archive_read_support_filter_all(ar) == ARCHIVE_OK); default: return false; } @@ -144,6 +144,9 @@ auto ArchiveOps::EnableWriteFormats(archive* aw, ArchiveType type) std::string(archive_error_string(aw)); } } break; + case ArchiveType::TarAuto: + return std::string( + "ArchiveOps: Writing a tarball-type archive must be explicit!"); } return std::nullopt; // success! } @@ -157,6 +160,7 @@ auto ArchiveOps::EnableReadFormats(archive* ar, ArchiveType type) std::string(archive_error_string(ar)); } } break; + case ArchiveType::TarAuto: case ArchiveType::Tar: case ArchiveType::TarGz: case ArchiveType::TarBz2: diff --git a/src/other_tools/utils/archive_ops.hpp b/src/other_tools/utils/archive_ops.hpp index 6ad5b7c4..74fcf39c 100644 --- a/src/other_tools/utils/archive_ops.hpp +++ b/src/other_tools/utils/archive_ops.hpp @@ -25,7 +25,14 @@ using archive = struct archive; using archive_entry = struct archive_entry; } -enum class ArchiveType : size_t { Zip, Tar, TarGz, TarBz2, TarXz }; +enum class ArchiveType : size_t { + Zip, + Tar, // uncompressed + TarGz, + TarBz2, + TarXz, + TarAuto, // autodetect tarball-type archives +}; /// \brief Class handling archiving and unarchiving operations via libarchive class ArchiveOps { |