Merge pull request #5554 from cakebaker/mv_no_target_directory

mv: fix issue with -T and destination ending with "/"
This commit is contained in:
Sylvestre Ledru 2023-12-07 14:13:06 +01:00 committed by GitHub
commit ca024abe31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -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());
}

View file

@ -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!();