From 1c6317af76afbef7f2e8a02987bccb9a66339f1c Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 22 Dec 2023 17:03:59 +0100 Subject: [PATCH] mv: allow dest with slash when using --update --- src/uu/mv/src/mv.rs | 6 +++++- tests/by-util/test_mv.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index a042acb87..dec6d3ad3 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -341,7 +341,11 @@ 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 && !opts.no_target_dir { + if path_ends_with_terminator(target) + && !target_is_dir + && !opts.no_target_dir + && opts.update != UpdateMode::ReplaceIfOlder + { return Err(MvError::FailedToAccessNotADirectory(target.quote().to_string()).into()); } diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 3fb002dc3..75500ac63 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -905,6 +905,20 @@ fn test_mv_update_option() { assert!(!at.file_exists(file_b)); } +#[test] +fn test_mv_update_with_dest_ending_with_slash() { + let (at, mut ucmd) = at_and_ucmd!(); + let source = "source"; + let dest = "destination/"; + + at.mkdir("source"); + + ucmd.arg("--update").arg(source).arg(dest).succeeds(); + + assert!(!at.dir_exists(source)); + assert!(at.dir_exists(dest)); +} + #[test] fn test_mv_arg_update_none() { let (at, mut ucmd) = at_and_ucmd!();