mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cp: show no "same file" error for --link a a
This commit is contained in:
parent
cbf42189a2
commit
7ddeba4b98
2 changed files with 18 additions and 0 deletions
|
@ -150,6 +150,7 @@ pub enum TargetType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copy action to perform
|
/// Copy action to perform
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub enum CopyMode {
|
pub enum CopyMode {
|
||||||
Link,
|
Link,
|
||||||
SymLink,
|
SymLink,
|
||||||
|
@ -1714,6 +1715,7 @@ fn copy_file(
|
||||||
&& !options.force()
|
&& !options.force()
|
||||||
&& options.backup == BackupMode::NoBackup
|
&& options.backup == BackupMode::NoBackup
|
||||||
&& source != dest
|
&& source != dest
|
||||||
|
|| (source == dest && options.copy_mode == CopyMode::Link)
|
||||||
{
|
{
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
@ -566,6 +566,22 @@ fn test_cp_arg_link_with_dest_hardlink_to_source() {
|
||||||
assert!(at.file_exists(hardlink));
|
assert!(at.file_exists(hardlink));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn test_cp_arg_link_with_same_file() {
|
||||||
|
use std::os::linux::fs::MetadataExt;
|
||||||
|
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let file = "file";
|
||||||
|
|
||||||
|
at.touch(file);
|
||||||
|
|
||||||
|
ucmd.args(&["--link", file, file]).succeeds();
|
||||||
|
|
||||||
|
assert_eq!(at.metadata(file).st_nlink(), 1);
|
||||||
|
assert!(at.file_exists(file));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_arg_symlink() {
|
fn test_cp_arg_symlink() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue