mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
mv: 'mv source hardlink' should fail
fixes: tests/mv/force.sh
This commit is contained in:
@@ -18,7 +18,7 @@ path = "src/mv.rs"
|
||||
clap = { workspace=true }
|
||||
fs_extra = { workspace=true }
|
||||
indicatif = { workspace=true }
|
||||
uucore = { workspace=true }
|
||||
uucore = { workspace=true, features=["fs"] }
|
||||
|
||||
[[bin]]
|
||||
name = "mv"
|
||||
|
||||
+2
-1
@@ -25,6 +25,7 @@ use std::path::{Path, PathBuf};
|
||||
use uucore::backup_control::{self, BackupMode};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError, UUsageError};
|
||||
use uucore::fs::are_hardlinks_to_same_file;
|
||||
use uucore::update_control::{self, UpdateMode};
|
||||
use uucore::{format_usage, help_about, help_section, help_usage, prompt_yes, show};
|
||||
|
||||
@@ -268,7 +269,7 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> {
|
||||
}
|
||||
|
||||
// GNU semantics are: if the source and target are the same, no move occurs and we print an error
|
||||
if source.eq(target) {
|
||||
if source.eq(target) || are_hardlinks_to_same_file(source, target) {
|
||||
// Done to match GNU semantics for the dot file
|
||||
if source.eq(Path::new(".")) || source.ends_with("/.") || source.is_file() {
|
||||
return Err(MvError::SameFile(
|
||||
|
||||
@@ -400,6 +400,23 @@ fn test_mv_same_file() {
|
||||
.stderr_is(format!("mv: '{file_a}' and '{file_a}' are the same file\n",));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_mv_same_hardlink() {
|
||||
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)
|
||||
.fails()
|
||||
.stderr_is(format!("mv: '{file_a}' and '{file_b}' are the same file\n",));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_same_file_not_dot_dir() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
Reference in New Issue
Block a user