Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change message when decompressing in current directory #119

Merged
merged 2 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
CompressionFormat::{self, *},
},
info, oof,
utils::nice_directory_display,
utils::to_utf,
utils::{self, dir_is_empty},
Error,
Expand Down Expand Up @@ -318,7 +319,7 @@ fn decompress_file(
utils::create_dir_if_non_existent(output_folder)?;
let zip_archive = zip::ZipArchive::new(reader)?;
let _files = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?;
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
return Ok(());
}

Expand Down Expand Up @@ -352,31 +353,31 @@ fn decompress_file(
let mut writer = fs::File::create(&output_path)?;

io::copy(&mut reader, &mut writer)?;
info!("Successfully decompressed archive in '{}'.", to_utf(output_path));
info!("Successfully decompressed archive in {}.", nice_directory_display(output_path));
}
Tar => {
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
}
Tgz => {
let reader = chain_reader_decoder(&Gzip, reader)?;
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
}
Tbz => {
let reader = chain_reader_decoder(&Bzip, reader)?;
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
}
Tlzma => {
let reader = chain_reader_decoder(&Lzma, reader)?;
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
}
Tzst => {
let reader = chain_reader_decoder(&Zstd, reader)?;
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
}
Zip => {
eprintln!("Compressing first into .zip.");
Expand All @@ -392,7 +393,7 @@ fn decompress_file(

let _ = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?;

info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ pub fn to_utf(os_str: impl AsRef<OsStr>) -> String {
text.trim_matches('"').to_string()
}

pub fn nice_directory_display(os_str: impl AsRef<OsStr>) -> String {
let text = to_utf(os_str);
if text == "." {
"current directory".to_string()
} else {
format!("'{}'", text)
}
}

pub struct Bytes {
bytes: f64,
}
Expand Down