diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 5bbf0eada8d..831b362ae71 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -255,7 +255,9 @@ fn handle_two_paths(source: &Path, target: &Path, b: &Behavior) -> UResult<()> { return Err(MvError::NoSuchFile(source.quote().to_string()).into()); } - if source.eq(target) || are_hardlinks_to_same_file(source, target) { + if (source.eq(target) || are_hardlinks_to_same_file(source, target)) + && b.backup != BackupMode::SimpleBackup + { if source.eq(Path::new(".")) || source.ends_with("/.") || source.is_file() { return Err( MvError::SameFile(source.quote().to_string(), target.quote().to_string()).into(), diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 93955711d33..7a1f5cd5b5a 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -417,6 +417,23 @@ fn test_mv_same_hardlink() { .stderr_is(format!("mv: '{file_a}' and '{file_b}' are the same file\n",)); } +#[test] +#[cfg(unix)] +fn test_mv_same_hardlink_backup_simple() { + let (at, mut ucmd) = at_and_ucmd!(); + let file_a = "test_mv_same_file_a"; + let file_b = "test_mv_same_file_b"; + at.touch(file_a); + + at.hard_link(file_a, file_b); + + at.touch(file_a); + ucmd.arg(file_a) + .arg(file_b) + .arg("--backup=simple") + .succeeds(); +} + #[test] fn test_mv_same_file_not_dot_dir() { let (at, mut ucmd) = at_and_ucmd!();