mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Merge pull request #3383 from sudosmile/main
mv: add OverwriteMode match in specific case
This commit is contained in:
commit
0f59af22d5
2 changed files with 23 additions and 0 deletions
|
@ -258,6 +258,16 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> {
|
||||||
move_files_into_dir(&[source.clone()], target, b)
|
move_files_into_dir(&[source.clone()], target, b)
|
||||||
}
|
}
|
||||||
} else if target.exists() && source.is_dir() {
|
} else if target.exists() && source.is_dir() {
|
||||||
|
match b.overwrite {
|
||||||
|
OverwriteMode::NoClobber => return Ok(()),
|
||||||
|
OverwriteMode::Interactive => {
|
||||||
|
println!("{}: overwrite {}? ", uucore::util_name(), target.quote());
|
||||||
|
if !read_yes() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OverwriteMode::Force => {}
|
||||||
|
};
|
||||||
Err(MvError::NonDirectoryToDirectory(
|
Err(MvError::NonDirectoryToDirectory(
|
||||||
source.quote().to_string(),
|
source.quote().to_string(),
|
||||||
target.quote().to_string(),
|
target.quote().to_string(),
|
||||||
|
|
|
@ -748,6 +748,19 @@ fn test_mv_errors() {
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_str()
|
.stderr_str()
|
||||||
.is_empty());
|
.is_empty());
|
||||||
|
|
||||||
|
// $ at.mkdir dir && at.touch file
|
||||||
|
// $ mv -i dir file
|
||||||
|
// err == mv: cannot overwrite non-directory 'file' with directory 'dir'
|
||||||
|
assert!(!scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(dir)
|
||||||
|
.arg(file_a)
|
||||||
|
.pipe_in("y")
|
||||||
|
.fails()
|
||||||
|
.stderr_str()
|
||||||
|
.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue