Skip to content

Commit

Permalink
mv --backup=simple a b on hard links should not fail
Browse files Browse the repository at this point in the history
touch a
ln a b
./target/debug/coreutils mv --backup=simple a b

GNU: tests/mv/hard-4.sh
  • Loading branch information
sylvestre committed May 8, 2023
1 parent 1b99376 commit 594f81a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
17 changes: 17 additions & 0 deletions tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
Expand Down

0 comments on commit 594f81a

Please sign in to comment.