mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +00:00
fix not overwriting a folder when compressing
This commit is contained in:
parent
7fdedac8da
commit
cdd1b530be
@ -114,7 +114,6 @@ pub fn compress_files(
|
||||
if !formats.is_empty() {
|
||||
warn_user_about_loading_zip_in_memory();
|
||||
|
||||
// give user the option to continue compressing after warning is shown
|
||||
if !user_wants_to_continue(output_path, question_policy, QuestionAction::Compression)? {
|
||||
return Ok(false);
|
||||
}
|
||||
|
@ -104,12 +104,10 @@ pub fn decompress_file(
|
||||
Gzip | Bzip | Lz4 | Lzma | Snappy | Zstd => {
|
||||
reader = chain_reader_decoder(&first_extension, reader)?;
|
||||
|
||||
let writer = utils::create_or_ask_overwrite(&output_file_path, question_policy)?;
|
||||
if writer.is_none() {
|
||||
// Means that the user doesn't want to overwrite
|
||||
return Ok(());
|
||||
}
|
||||
let mut writer = writer.unwrap();
|
||||
let mut writer = match utils::ask_to_create_file(&output_file_path, question_policy)? {
|
||||
Some(file) => file,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
if is_running_in_accessible_mode() {
|
||||
io::copy(&mut reader, &mut writer)?;
|
||||
@ -139,7 +137,6 @@ pub fn decompress_file(
|
||||
if formats.len() > 1 {
|
||||
warn_user_about_loading_zip_in_memory();
|
||||
|
||||
// give user the option to continue decompressing after warning is shown
|
||||
if !user_wants_to_continue(input_file_path, question_policy, QuestionAction::Decompression)? {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -67,7 +67,6 @@ pub fn list_archive_contents(
|
||||
if formats.len() > 1 {
|
||||
warn_user_about_loading_zip_in_memory();
|
||||
|
||||
// give user the option to continue decompressing after warning is shown
|
||||
if !user_wants_to_continue(archive_path, question_policy, QuestionAction::Decompression)? {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -162,12 +162,11 @@ pub fn run(
|
||||
return Err(error.into());
|
||||
}
|
||||
|
||||
if output_path.exists() && !utils::user_wants_to_overwrite(&output_path, question_policy)? {
|
||||
// User does not want to overwrite this file, skip and return without any errors
|
||||
return Ok(());
|
||||
}
|
||||
let output_file = match utils::ask_to_create_file(&output_path, question_policy)? {
|
||||
Some(writer) => writer,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
let output_file = fs::File::create(&output_path)?;
|
||||
let compress_result = compress_files(
|
||||
files,
|
||||
formats,
|
||||
|
@ -15,7 +15,7 @@ pub use fs::{
|
||||
cd_into_same_dir_as, clear_path, create_dir_if_non_existent, dir_is_empty, is_symlink, try_infer_extension,
|
||||
};
|
||||
pub use question::{
|
||||
create_or_ask_overwrite, user_wants_to_continue, user_wants_to_overwrite, QuestionAction, QuestionPolicy,
|
||||
ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, QuestionAction, QuestionPolicy,
|
||||
};
|
||||
pub use utf8::{get_invalid_utf8_paths, is_invalid_utf8};
|
||||
|
||||
|
@ -54,7 +54,7 @@ pub fn user_wants_to_overwrite(path: &Path, question_policy: QuestionPolicy) ->
|
||||
|
||||
/// Create the file if it doesn't exist and if it does then ask to overwrite it.
|
||||
/// If the user doesn't want to overwrite then we return [`Ok(None)`]
|
||||
pub fn create_or_ask_overwrite(path: &Path, question_policy: QuestionPolicy) -> Result<Option<fs::File>> {
|
||||
pub fn ask_to_create_file(path: &Path, question_policy: QuestionPolicy) -> Result<Option<fs::File>> {
|
||||
match fs::OpenOptions::new().write(true).create_new(true).open(path) {
|
||||
Ok(w) => Ok(Some(w)),
|
||||
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user