mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +00:00
Merge pull request #5554 from cakebaker/mv_no_target_directory
mv: fix issue with -T and destination ending with "/"
This commit is contained in:
commit
ca024abe31
2 changed files with 27 additions and 1 deletions
|
@ -341,7 +341,7 @@ fn handle_two_paths(source: &Path, target: &Path, opts: &Options) -> UResult<()>
|
|||
|
||||
let target_is_dir = target.is_dir();
|
||||
|
||||
if path_ends_with_terminator(target) && !target_is_dir {
|
||||
if path_ends_with_terminator(target) && !target_is_dir && !opts.no_target_dir {
|
||||
return Err(MvError::FailedToAccessNotADirectory(target.quote().to_string()).into());
|
||||
}
|
||||
|
||||
|
|
|
@ -1158,6 +1158,32 @@ fn test_mv_overwrite_dir() {
|
|||
assert!(at.dir_exists(dir_b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_no_target_dir_with_dest_not_existing() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let dir_a = "a";
|
||||
let dir_b = "b";
|
||||
|
||||
at.mkdir(dir_a);
|
||||
ucmd.arg("-T").arg(dir_a).arg(dir_b).succeeds().no_output();
|
||||
|
||||
assert!(!at.dir_exists(dir_a));
|
||||
assert!(at.dir_exists(dir_b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_no_target_dir_with_dest_not_existing_and_ending_with_slash() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let dir_a = "a";
|
||||
let dir_b = "b/";
|
||||
|
||||
at.mkdir(dir_a);
|
||||
ucmd.arg("-T").arg(dir_a).arg(dir_b).succeeds().no_output();
|
||||
|
||||
assert!(!at.dir_exists(dir_a));
|
||||
assert!(at.dir_exists(dir_b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_overwrite_nonempty_dir() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
Loading…
Reference in a new issue