diff --git a/src/decompressors/tar.rs b/src/decompressors/tar.rs index c384ada..13ef979 100644 --- a/src/decompressors/tar.rs +++ b/src/decompressors/tar.rs @@ -37,7 +37,8 @@ impl TarDecompressor { let file_path = PathBuf::from(into).join(file.path()?); if file_path.exists() { let file_path_str = &*file_path.to_string_lossy(); - if confirm.ask(Some(file_path_str))? { + if !confirm.ask(Some(file_path_str))? { + // The user does not want to overwrite the file continue; } } @@ -51,7 +52,7 @@ impl TarDecompressor { file.size() ); - let file_path = fs::canonicalize(into.join(file.path()?))?; + let file_path = fs::canonicalize(file_path)?; files_unpacked.push(file_path); } diff --git a/src/decompressors/zip.rs b/src/decompressors/zip.rs index 6e414d2..40e8441 100644 --- a/src/decompressors/zip.rs +++ b/src/decompressors/zip.rs @@ -53,7 +53,8 @@ impl ZipDecompressor { let file_path = into.join(file_path); if file_path.exists() { let file_path_str = &*file_path.as_path().to_string_lossy(); - if confirm.ask(Some(file_path_str))? { + if !confirm.ask(Some(file_path_str))? { + // The user does not want to overwrite the file continue; } } diff --git a/src/evaluator.rs b/src/evaluator.rs index 8e923b1..d913bea 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -13,6 +13,7 @@ use crate::{ TarDecompressor, ZipDecompressor, }, extension::{CompressionFormat, Extension}, + dialogs::Confirmation, file::File, utils, }; @@ -148,9 +149,18 @@ impl Evaluator { } fn compress_files(files: Vec, mut output: File) -> crate::Result<()> { + let confirm = Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")); let (first_compressor, second_compressor) = Self::get_compressor(&output)?; let output_path = output.path.clone(); + if output_path.exists() { + let output_path_str = &*output_path.to_string_lossy(); + if !confirm.ask(Some(output_path_str))? { + // The user does not want to overwrite the file + return Ok(()); + } + } + let bytes = match first_compressor { Some(first_compressor) => {