mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
evaluator: Add confirmation dialog for file overwriting
This commit is contained in:
parent
03d6fc1e60
commit
40fb926d80
@ -37,7 +37,8 @@ impl TarDecompressor {
|
|||||||
let file_path = PathBuf::from(into).join(file.path()?);
|
let file_path = PathBuf::from(into).join(file.path()?);
|
||||||
if file_path.exists() {
|
if file_path.exists() {
|
||||||
let file_path_str = &*file_path.to_string_lossy();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,7 +52,7 @@ impl TarDecompressor {
|
|||||||
file.size()
|
file.size()
|
||||||
);
|
);
|
||||||
|
|
||||||
let file_path = fs::canonicalize(into.join(file.path()?))?;
|
let file_path = fs::canonicalize(file_path)?;
|
||||||
files_unpacked.push(file_path);
|
files_unpacked.push(file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,8 @@ impl ZipDecompressor {
|
|||||||
let file_path = into.join(file_path);
|
let file_path = into.join(file_path);
|
||||||
if file_path.exists() {
|
if file_path.exists() {
|
||||||
let file_path_str = &*file_path.as_path().to_string_lossy();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ use crate::{
|
|||||||
TarDecompressor, ZipDecompressor,
|
TarDecompressor, ZipDecompressor,
|
||||||
},
|
},
|
||||||
extension::{CompressionFormat, Extension},
|
extension::{CompressionFormat, Extension},
|
||||||
|
dialogs::Confirmation,
|
||||||
file::File,
|
file::File,
|
||||||
utils,
|
utils,
|
||||||
};
|
};
|
||||||
@ -148,9 +149,18 @@ impl Evaluator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compress_files(files: Vec<PathBuf>, mut output: File) -> crate::Result<()> {
|
fn compress_files(files: Vec<PathBuf>, 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 (first_compressor, second_compressor) = Self::get_compressor(&output)?;
|
||||||
|
|
||||||
let output_path = output.path.clone();
|
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 {
|
let bytes = match first_compressor {
|
||||||
Some(first_compressor) => {
|
Some(first_compressor) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user