From b9e53e809379532573202f5e5f7a19d1b8441a14 Mon Sep 17 00:00:00 2001 From: albus-droid Date: Wed, 4 Jun 2025 12:00:46 +0000 Subject: [PATCH 1/3] Change condition to not fail for dangling symlinks The function `move_files_into_dir` had a condition that failed when a dangling symlink was moved into a folder, which resulted in a file or directory doesn't exist error --- src/uu/mv/src/mv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index edfa505c521..c7f920204cd 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; } From 1ba34e4d2311a378fc2332b627e9079d83bdea9f Mon Sep 17 00:00:00 2001 From: albus-droid Date: Wed, 4 Jun 2025 05:17:49 -0400 Subject: [PATCH 2/3] Added a test case --- tests/by-util/test_mv.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 577f6a75899..280649359fe 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() { From 4ab58ac71e1500aff960cc4ba814d94e3caf330d Mon Sep 17 00:00:00 2001 From: albus-droid Date: Wed, 4 Jun 2025 05:34:45 -0400 Subject: [PATCH 3/3] Fix linting and style issues --- tests/by-util/test_mv.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 280649359fe..b20c4b2b644 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -446,11 +446,11 @@ fn test_mv_same_hardlink() { #[test] #[cfg(all(unix, not(target_os = "android")))] fn test_mv_dangling_symlink_to_folder() { - let (at, mut ucmd) = at_and_ucmd!(); + 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"));