Skip to content

cp: create removed destinations exclusively - #15330

Draft
abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:cp-recreate-dest-exclusive
Draft

abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:cp-recreate-dest-exclusive

Conversation

@abendrothj

@abendrothj abendrothj commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #15329

When the destination was missing, or cp had removed or renamed it (--remove-destination, -f, --backup), cp created the new file without O_EXCL. Whatever appeared at that name in between was opened, and a symlink was followed.

cp now creates the file exclusively in those cases and fails if anything is there, with GNU's messages. A destination that is overwritten in place is opened as before. The flag lives in uucore's create_dest_restrictive, where exclusive replaces nofollow. Its only nofollow caller, mv's cross-device fallback, now creates exclusively too, as GNU mv does. mv can't be paused between its removal and the create, so that path has no test of its own; the uucore unit tests cover the exclusive create. --attributes-only creates exclusively on Windows too; the Windows data copy still uses fs::copy. util/check-safe-traversal.sh accepts O_EXCL as well as O_NOFOLLOW for mv's create.

Checked against GNU coreutils 9.12 for --remove-destination with a symlink, a dangling symlink and a regular file created after the removal: messages and exit status match. Added test_cp_does_not_open_dest_recreated_after_removal, which fails without the change on macOS and Linux.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 04:19

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codspeed

codspeed Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 13.13%

1 warning, 1 note

⚠️ 118 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 2 improved benchmarks
✅ 399 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation true_consecutive_calls 350.2 ns 294.7 ns +18.85%
⚡ Memory du_deep_tree[(100, 3)] 82.4 KB 76.5 KB +7.68%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing abendrothj:cp-recreate-dest-exclusive (9d7881e) with main (29550e9)2

Open in CodSpeed

Footnotes

  1. 70 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. ↩

  2. No successful run was found on main (744e299) during the generation of this report, so 29550e9 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Comment thread src/uu/cp/src/cp.rs Outdated
Comment thread src/uu/cp/src/platform/macos.rs
Comment thread tests/by-util/test_cp.rs Outdated
@abendrothj
abendrothj force-pushed the cp-recreate-dest-exclusive branch from 8270ad8 to be468b3 Compare October 14, 2026 22:08
Copilot AI balanced review requested due to automatic review settings October 14, 2026 22:08

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

On macOS, a streamed destination is now created at 0600, as on Linux,
instead of 0622 minus the umask.
Copilot AI balanced review requested due to automatic review settings October 22, 2026 06:44
@abendrothj
abendrothj force-pushed the cp-recreate-dest-exclusive branch from be468b3 to 9d7881e Compare October 22, 2026 06:44

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@abendrothj
abendrothj marked this pull request as draft October 23, 2026 07:30

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 --remove-destination opens a file that appears after the removal

3 participants