diff options
author | Rummskartoffel <Rummskartoffel@protonmail.com> | 2022-01-17 22:30:44 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-23 20:52:16 +0000 |
commit | 5f639493f030ebb78b1a232b781eb596793d70b3 (patch) | |
tree | df4d66936d1cd5817faacb2886ad7d0726205544 /Userland | |
parent | e8ae0541d9acca41e704e62043495be51449bb39 (diff) | |
download | serenity-5f639493f030ebb78b1a232b781eb596793d70b3.zip |
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`.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Utilities/gunzip.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Userland/Utilities/gunzip.cpp b/Userland/Utilities/gunzip.cpp index 30902c22d7..cd8879577a 100644 --- a/Userland/Utilities/gunzip.cpp +++ b/Userland/Utilities/gunzip.cpp @@ -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)); |