Skip to content

Commit e08c43a

Browse files
authored
Merge pull request #6496 from djedi23/6267-cp-preserved-hardlinks-are-not-reported-in--verbose
cp: fix preserved hardlinks are not reported in --verbose
2 parents 2244adb + 2e223df commit e08c43a

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/uu/cp/src/cp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,10 @@ fn copy_file(
21082108
.into());
21092109
}
21102110

2111+
if options.verbose {
2112+
print_verbose_output(options.parents, progress_bar, source, dest);
2113+
}
2114+
21112115
if options.preserve_hard_links() {
21122116
// if we encounter a matching device/inode pair in the source tree
21132117
// we can arrange to create a hard link between the corresponding names
@@ -2121,10 +2125,6 @@ fn copy_file(
21212125
};
21222126
}
21232127

2124-
if options.verbose {
2125-
print_verbose_output(options.parents, progress_bar, source, dest);
2126-
}
2127-
21282128
// Calculate the context upfront before canonicalizing the path
21292129
let context = context_for(source, dest);
21302130
let context = context.as_str();

tests/by-util/test_cp.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,36 @@ fn test_cp_arg_link_with_same_file() {
608608
assert!(at.file_exists(file));
609609
}
610610

611+
#[test]
612+
#[cfg(target_os = "linux")]
613+
fn test_cp_verbose_preserved_link_to_dir() {
614+
use std::os::linux::fs::MetadataExt;
615+
616+
let (at, mut ucmd) = at_and_ucmd!();
617+
let file = "file";
618+
let hardlink = "hardlink";
619+
let dir = "dir";
620+
let dst_file = "dir/file";
621+
let dst_hardlink = "dir/hardlink";
622+
623+
at.touch(file);
624+
at.hard_link(file, hardlink);
625+
at.mkdir(dir);
626+
627+
ucmd.args(&["-d", "--verbose", file, hardlink, dir])
628+
.succeeds()
629+
.stdout_is("'file' -> 'dir/file'\n'hardlink' -> 'dir/hardlink'\n");
630+
631+
assert!(at.file_exists(dst_file));
632+
assert!(at.file_exists(dst_hardlink));
633+
assert_eq!(at.metadata(dst_file).st_nlink(), 2);
634+
assert_eq!(at.metadata(dst_hardlink).st_nlink(), 2);
635+
assert_eq!(
636+
at.metadata(dst_file).st_ino(),
637+
at.metadata(dst_hardlink).st_ino()
638+
);
639+
}
640+
611641
#[test]
612642
fn test_cp_arg_symlink() {
613643
let (at, mut ucmd) = at_and_ucmd!();

0 commit comments

Comments
 (0)