gunzip: Don't truncate output filename when input file suffix is omitted

Before this commit, `$ gunzip abcd` would incorrectly uncompress
`abcd.gz` to `a` instead of to `abcd`.
This commit is contained in:
Rummskartoffel 2022-01-17 22:30:44 +01:00 committed by Linus Groh
parent e8ae0541d9
commit 5f639493f0
Notes: sideshowbarker 2024-07-17 20:22:28 +09:00

View file

@ -43,12 +43,14 @@ ErrorOr<int> serenity_main(Main::Arguments args)
for (auto filename : filenames) {
String input_filename;
if (filename.ends_with(".gz"))
String output_filename;
if (filename.ends_with(".gz")) {
input_filename = filename;
else
output_filename = filename.substring_view(0, filename.length() - 3);
} else {
input_filename = String::formatted("{}.gz", filename);
const auto output_filename = filename.substring_view(0, filename.length() - 3);
output_filename = filename;
}
auto input_stream_result = TRY(Core::InputFileStream::open_buffered(input_filename));