mv: moving dangling symlinks into directories (#8064)

* Fix linting and style issues

* 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

* Added a test case
This commit is contained in:
ALBIN BABU VARGHESE
2025-06-04 17:25:53 +02:00
committed by GitHub
parent c332d96203
commit a7a493a604
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -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;
}
+13
View File
@@ -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() {