Skip to content

cp: create removed destinations exclusively - #15330

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

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 just removed it (--remove-destination, -f on a read-only file, --backup of a symlink), cp created the new file without O_EXCL: anything that 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 something is there, with GNU 9.12's messages; a destination overwritten in place is opened as before. uucore's create_dest_restrictive takes ExistingDest::{Truncate, Refuse} instead of nofollow. Its only nofollow caller, mv's cross-device fallback, now creates exclusively too. On macOS a streamed destination is now created at 0600, as on Linux.

The new test holds cp between the removal and the create with a FIFO source, and fails without the change on Linux and macOS. util/check-safe-traversal.sh checks that --remove-destination creates a regular file with O_EXCL, and that mv's create uses it. The missing-destination case can't be held there and relies on the uucore unit tests. With --backup, a refused create leaves the backup in place instead of restoring it as GNU does (#16240).

--attributes-only creates exclusively on every platform. The Windows and WASI data copy still uses fs::copy; a follow-up will use CopyFileExW with COPY_FILE_FAIL_IF_EXISTS and create_new.

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
Contributor

Merging this PR will degrade performance by 3.15%

3 warnings, 1 note

⚠️ 122 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

⚠️ 7 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 4 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

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

⚡ 4 improved benchmarks
❌ 3 regressed benchmarks
✅ 258 untouched benchmarks
⏩ 218 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation socket_addrs_direct[100000] 104.9 µs 131.4 µs -20.2%
❌ CPU Simulation hostname_ip_lookup[100000] 155.7 µs 184 µs -15.35%
❌ CPU Simulation df_deep_directory 881.4 µs 928.7 µs -5.1%
⚡ CPU Simulation split_number_chunks_round_robin 32.8 ms 28.9 ms +13.4%
⚡ CPU Simulation dd_copy_with_seek 5 ms 4.9 ms +3.27%
⚡ CPU Simulation dd_copy_8k_blocks 1.9 ms 1.9 ms +3.22%
⚡ CPU Simulation dd_copy_with_skip 4.9 ms 4.8 ms +3.15%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing abendrothj:cp-recreate-dest-exclusive (cd03ce5) with main (e1b90fa)

Open in CodSpeed

Footnotes

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

Comment thread src/uu/cp/src/cp.rs Resolved
Comment thread src/uu/cp/src/platform/macos.rs Resolved
Comment thread tests/by-util/test_cp.rs Resolved
@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.

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
@sylvestre

Copy link
Copy Markdown
Contributor

sorry but it needs to be rebased

@abendrothj
abendrothj force-pushed the cp-recreate-dest-exclusive branch from 9d7881e to 0078890 Compare November 7, 2026 06:33
@abendrothj
abendrothj force-pushed the cp-recreate-dest-exclusive branch from 0078890 to fda8bd0 Compare November 10, 2026 00:23
@abendrothj
abendrothj marked this pull request as ready for review November 10, 2026 00:23
Copilot AI balanced review requested due to automatic review settings November 10, 2026 00:23

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 insufficient remaining quota. Try requesting a review at a lower effort level.

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

Copy link
Copy Markdown
Contributor Author

Rebased, thanks! I also tightened the description while I was at it.

Comment thread tests/by-util/test_cp.rs Resolved
@abendrothj
abendrothj force-pushed the cp-recreate-dest-exclusive branch from fda8bd0 to abcb48f Compare November 11, 2026 02:07
Copilot AI balanced review requested due to automatic review settings November 11, 2026 02:07

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 insufficient remaining quota. Try requesting a review at a lower effort level.

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.

cp and mv's cross-device copy create a removed or missing destination
with O_EXCL, as GNU does; on macOS streamed ones are created 0600.
@abendrothj
abendrothj force-pushed the cp-recreate-dest-exclusive branch from abcb48f to cd03ce5 Compare November 19, 2026 07:38
Copilot AI balanced review requested due to automatic review settings November 19, 2026 07:38

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 insufficient remaining quota. Try requesting a review at a lower effort level.

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.

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