tar: Add partial support for XZ-compressed archives :^)

This commit is contained in:
Tim Schumacher 2023-03-14 02:59:11 +01:00 committed by Andreas Kling
parent a61c120b3f
commit 16cb127c0b

View file

@ -11,6 +11,7 @@
#include <LibArchive/TarStream.h>
#include <LibCompress/Gzip.h>
#include <LibCompress/Lzma.h>
#include <LibCompress/Xz.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DeprecatedFile.h>
#include <LibCore/DirIterator.h>
@ -32,6 +33,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
bool verbose = false;
bool gzip = false;
bool lzma = false;
bool xz = false;
bool no_auto_compress = false;
StringView archive_file;
bool dereference;
@ -45,6 +47,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(verbose, "Print paths", "verbose", 'v');
args_parser.add_option(gzip, "Compress or decompress file using gzip", "gzip", 'z');
args_parser.add_option(lzma, "Compress or decompress file using lzma", "lzma", 0);
args_parser.add_option(xz, "Compress or decompress file using xz", "xz", 'J');
args_parser.add_option(no_auto_compress, "Do not use the archive suffix to select the compression algorithm", "no-auto-compress", 0);
args_parser.add_option(directory, "Directory to extract to/create from", "directory", 'C', "DIRECTORY");
args_parser.add_option(archive_file, "Archive file", "file", 'f', "FILE");
@ -62,6 +65,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
gzip = true;
if (archive_file.ends_with(".lzma"sv))
lzma = true;
if (archive_file.ends_with(".xz"sv))
xz = true;
}
if (list || extract) {
@ -76,6 +81,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (lzma)
input_stream = TRY(Compress::LzmaDecompressor::create_from_container(move(input_stream)));
if (xz)
input_stream = TRY(Compress::XzDecompressor::create(move(input_stream)));
auto tar_stream = TRY(Archive::TarInputStream::construct(move(input_stream)));
HashMap<DeprecatedString, DeprecatedString> global_overrides;
@ -227,6 +235,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (lzma)
TODO();
if (xz)
TODO();
Archive::TarOutputStream tar_stream(move(output_stream));
auto add_file = [&](DeprecatedString path) -> ErrorOr<void> {