Utilities/tar: Open archive file before changing directory

Otherwise the utility will fail to open the archive file because it's
presumably not in the chosen directory.
This commit is contained in:
Liav A.
2024-06-01 11:05:42 +03:00
committed by Tim Schumacher
parent d906255cbb
commit a7aa843bcc

View File

@@ -72,11 +72,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
if (list || extract) {
NonnullOwnPtr<Stream> input_stream = TRY(Core::InputBufferedFile::create(TRY(Core::File::open_file_or_standard_stream(archive_file, Core::File::OpenMode::Read))));
if (!directory.is_empty())
TRY(Core::System::chdir(directory));
NonnullOwnPtr<Stream> input_stream = TRY(Core::InputBufferedFile::create(TRY(Core::File::open_file_or_standard_stream(archive_file, Core::File::OpenMode::Read))));
if (gzip)
input_stream = make<Compress::GzipDecompressor>(move(input_stream));