Skip to content

Commit 2ba3a33

Browse files
authored
Merge pull request #8331 from julian-klode/fix-8330
cp: Fix --no-dereference --parents with symlink source
2 parents dd1b315 + b585e98 commit 2ba3a33

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/uu/cp/src/cp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ fn copy_source(
15021502
copied_files: &mut HashMap<FileInformation, PathBuf>,
15031503
) -> CopyResult<()> {
15041504
let source_path = Path::new(&source);
1505-
if source_path.is_dir() {
1505+
if source_path.is_dir() && (options.dereference || !source_path.is_symlink()) {
15061506
// Copy as directory
15071507
copy_directory(
15081508
progress_bar,

tests/by-util/test_cp.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6706,3 +6706,23 @@ fn test_cp_preserve_context_root() {
67066706
print!("Test skipped; requires root user");
67076707
}
67086708
}
6709+
6710+
#[test]
6711+
#[cfg(not(windows))]
6712+
fn test_cp_no_dereference_symlink_with_parents() {
6713+
let ts = TestScenario::new(util_name!());
6714+
let at = &ts.fixtures;
6715+
at.mkdir("directory");
6716+
at.symlink_file("directory", "symlink-to-directory");
6717+
6718+
ts.ucmd()
6719+
.args(&["--parents", "--no-dereference", "symlink-to-directory", "x"])
6720+
.fails()
6721+
.stderr_contains("with --parents, the destination must be a directory");
6722+
6723+
at.mkdir("x");
6724+
ts.ucmd()
6725+
.args(&["--parents", "--no-dereference", "symlink-to-directory", "x"])
6726+
.succeeds();
6727+
assert_eq!(at.resolve_link("x/symlink-to-directory"), "directory");
6728+
}

0 commit comments

Comments
 (0)