Skip to content

cp: preserve the source directory for recursive --parents copies ending in /. - #17051

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/cp-parents-trailing-dot-17050
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/cp-parents-trailing-dot-17050

Conversation

@limadog9

@limadog9 limadog9 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Use the full destination for a source ending in /. so refreshing an existing backup updates the intended directory. Regression tests cover relative and absolute source paths.

Closes #17050

Comment thread src/uu/cp/src/copydir.rs Outdated
let parents_dest = if options.parents {
// Strip the filesystem root (the empty path for a relative source)
// so even an absolute source stays underneath the target.
let prefix = root.ancestors().last().unwrap_or(root);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cp.rs construct_dest_path already computes this root (has_root() && cfg!(unix)). Could it be shared, so files and dirs agree on Windows too?

Comment thread tests/by-util/test_cp.rs Outdated
#[cfg(unix)]
#[uutests::wasi_ignore(HostPathsNotVisible)]
#[test]
fn test_cp_parents_recursive_absolute_source_ending_in_dot() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also changes cp -R --parents /abs/dir backup without the trailing /., please add a test for that case too

Comment thread src/uu/cp/src/copydir.rs
// A source ending in /. is walked relative to the directory itself.
// Its full --parents destination is therefore the traversal target.
if ends_with_dot_component(root) {
parents_dest.join(".")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why join(".")? is it only for the verbose output?

@limadog9
limadog9 force-pushed the fix/cp-parents-trailing-dot-17050 branch from d6ee835 to 808084d Compare December 1, 2026 20:21

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cp -R --parents reports/. overwrites an unrelated file in the backup root

2 participants