diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index edfa505c5..c7f920204 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -526,7 +526,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options) }; for sourcepath in files { - if !sourcepath.exists() { + if sourcepath.symlink_metadata().is_err() { show!(MvError::NoSuchFile(sourcepath.quote().to_string())); continue; } diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 577f6a758..b20c4b2b6 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -443,6 +443,19 @@ fn test_mv_same_hardlink() { .stderr_is(format!("mv: '{file_a}' and '{file_b}' are the same file\n")); } +#[test] +#[cfg(all(unix, not(target_os = "android")))] +fn test_mv_dangling_symlink_to_folder() { + let (at, mut ucmd) = at_and_ucmd!(); + + at.symlink_file("404", "abc"); + at.mkdir("x"); + + ucmd.arg("abc").arg("x").succeeds(); + + assert!(at.symlink_exists("x/abc")); +} + #[test] #[cfg(all(unix, not(target_os = "android")))] fn test_mv_same_symlink() {