mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
fix fatal error if read fails when compressing
This commit is contained in:
parent
4d2ccf4873
commit
2da497c1ca
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user