diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d05e643..6198604 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -9,7 +9,6 @@ use std::{ path::{Path, PathBuf}, }; -use fs_err as fs; use utils::colors; use crate::{ @@ -183,22 +182,13 @@ pub fn run( // about whether the command succeeded without such a message info!(accessible, "Successfully compressed '{}'.", to_utf(&output_path)); } else { - // If Ok(false) or Err() occurred, delete incomplete file - // Print an extra alert message pointing out that we left a possibly - // CORRUPTED FILE at `output_path` - if let Err(err) = fs::remove_file(&output_path) { + if let Err(_) = utils::remove_file_or_dir(&output_path) { eprintln!("{red}FATAL ERROR:\n", red = *colors::RED); eprintln!(" Please manually delete '{}'.", to_utf(&output_path)); eprintln!( " Compression failed and we could not delete '{}'.", to_utf(&output_path), ); - eprintln!( - " Error:{reset} {}{red}.{reset}\n", - err, - reset = *colors::RESET, - red = *colors::RED - ); } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e6808bf..e2c3130 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -12,7 +12,8 @@ mod question; pub use file_visibility::FileVisibilityPolicy; pub use formatting::{nice_directory_display, pretty_format_list_of_paths, strip_cur_dir, to_utf}; pub use fs::{ - cd_into_same_dir_as, clear_path, create_dir_if_non_existent, dir_is_empty, is_symlink, try_infer_extension, + cd_into_same_dir_as, clear_path, create_dir_if_non_existent, dir_is_empty, is_symlink, remove_file_or_dir, + try_infer_extension, }; pub use question::{ ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, QuestionAction, QuestionPolicy,