1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #5762 from cakebaker/cp_link_same_file

cp: show no "same file" error for `--link a a`
This commit is contained in:
Sylvestre Ledru 2024-01-14 23:29:33 +01:00 committed by GitHub
commit e3beda08ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View file

@ -150,6 +150,7 @@ pub enum TargetType {
}
/// Copy action to perform
#[derive(PartialEq)]
pub enum CopyMode {
Link,
SymLink,
@ -1714,6 +1715,7 @@ fn copy_file(
&& !options.force()
&& options.backup == BackupMode::NoBackup
&& source != dest
|| (source == dest && options.copy_mode == CopyMode::Link)
{
return Ok(());
}

View file

@ -566,6 +566,22 @@ fn test_cp_arg_link_with_dest_hardlink_to_source() {
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]
fn test_cp_arg_symlink() {
let (at, mut ucmd) = at_and_ucmd!();