mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
mv: 'mv source hardlink' should fail
fixes: tests/mv/force.sh
This commit is contained in:
parent
b7cf825887
commit
a5a39b6ba8
3 changed files with 20 additions and 2 deletions
|
@ -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"
|
||||
|
|
|
@ -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!();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue