1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #3383 from sudosmile/main

mv: add OverwriteMode match in specific case
This commit is contained in:
Sylvestre Ledru 2022-04-12 20:28:07 +02:00 committed by GitHub
commit 0f59af22d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View file

@ -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(),

View file

@ -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]