Skip to content

Conversation

@vikram-kangotra
Copy link
Contributor

@vikram-kangotra vikram-kangotra commented Nov 18, 2025

Previously, when copying to a destination that was created in the same cp call, the operation would fail with "will not overwrite just-created" for both files and directories. This change allows directories to be merged (matching GNU cp behavior) while still preventing file overwrites.

The fix checks if both the source and destination are directories before allowing the merge. If either is a file, the original error behavior is preserved to prevent accidental file overwrites.

Fixes the case where copying multiple directories to the same destination path would incorrectly error instead of merging their contents.

fixes: #9318

Previously, when copying to a destination that was created in the same
cp call, the operation would fail with "will not overwrite just-created"
for both files and directories. This change allows directories to be
merged (matching GNU cp behavior) while still preventing file
overwrites.

The fix checks if both the source and destination are directories
before allowing the merge. If either is a file, the original error
behavior is preserved to prevent accidental file overwrites.

Fixes the case where copying multiple directories to the same
destination path would incorrectly error instead of merging their
contents.

fixes: uutils#9318
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 18, 2025

CodSpeed Performance Report

Merging #9325 will not alter performance

Comparing vikram-kangotra:fix/cp-dir-merge (7ee3237) with main (b0f41e7)

Summary

✅ 126 untouched
⏩ 6 skipped1

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

Copy link
Contributor

@cakebaker cakebaker left a comment

Choose a reason for hiding this comment

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

The other changes look fine :)

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
@vikram-kangotra
Copy link
Contributor Author

@cakebaker Applied the suggestions, thanks!

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@cakebaker cakebaker merged commit 15d22c2 into uutils:main Nov 19, 2025
127 checks passed
@cakebaker
Copy link
Contributor

Thanks!

@vikram-kangotra vikram-kangotra deleted the fix/cp-dir-merge branch November 20, 2025 17:09
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 doesn't merge contents of folders when containing the same folders like GNU cp does

2 participants