1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

mv: -i show no error if overwriting is declined

This commit is contained in:
Daniel Hofstetter 2023-04-23 15:27:24 +02:00
parent 698bdf5f9a
commit e94f1d8eb7
2 changed files with 38 additions and 16 deletions

View file

@ -24,7 +24,7 @@ use std::os::windows;
use std::path::{Path, PathBuf};
use uucore::backup_control::{self, BackupMode};
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, USimpleError, UUsageError};
use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError, UUsageError};
use uucore::{format_usage, help_about, help_usage, prompt_yes, show};
use fs_extra::dir::{
@ -378,21 +378,23 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR
}
}
let rename_result = rename(sourcepath, &targetpath, b, multi_progress.as_ref())
.map_err_context(|| {
format!(
"cannot move {} to {}",
sourcepath.quote(),
targetpath.quote()
)
});
if let Err(e) = rename_result {
match multi_progress {
Some(ref pb) => pb.suspend(|| show!(e)),
None => show!(e),
};
};
match rename(sourcepath, &targetpath, b, multi_progress.as_ref()) {
Err(e) if e.to_string() == "" => set_exit_code(1),
Err(e) => {
let e = e.map_err_context(|| {
format!(
"cannot move {} to {}",
sourcepath.quote(),
targetpath.quote()
)
});
match multi_progress {
Some(ref pb) => pb.suspend(|| show!(e)),
None => show!(e),
};
}
Ok(()) => (),
}
if let Some(ref pb) = count_progress {
pb.inc(1);

View file

@ -181,6 +181,26 @@ fn test_mv_interactive() {
assert!(at.file_exists(file_b));
}
#[test]
fn test_mv_interactive_with_dir_as_target() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_mv_interactive_file";
let target_dir = "target";
at.mkdir(target_dir);
at.touch(file);
at.touch(format!("{target_dir}/{file}"));
ucmd.arg(file)
.arg(target_dir)
.arg("-i")
.pipe_in("n")
.fails()
.stderr_does_not_contain("cannot move")
.no_stdout();
}
#[test]
fn test_mv_arg_update_interactive() {
let (at, mut ucmd) = at_and_ucmd!();