Skip to content

cp: back up the destination by renaming it - #14889

Open
Smicry wants to merge 1 commit into
uutils:mainfrom
Smicry:fix/cp-backup-open-exe
Open

Smicry wants to merge 1 commit into
uutils:mainfrom
Smicry:fix/cp-backup-open-exe

Conversation

@Smicry

@Smicry Smicry commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Making the backup by copying reads the destination. On Windows that fails when the destination is a running image, which can be renamed but neither deleted nor overwritten in place, so cp --backup could not replace an executable that is in use. Move the destination aside instead, as GNU's backup_file_rename does.

cp FILE FILE still copies, since moving the destination aside there would take the source with it.

Fixes #3034

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)

@Smicry
Smicry force-pushed the fix/cp-backup-open-exe branch from 9f4ecbd to c99e9a8 Compare October 29, 2026 03:34
@codspeed

codspeed Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

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

✅ 11 untouched benchmarks
⏩ 472 skipped benchmarks1


Comparing Smicry:fix/cp-backup-open-exe (58d404d) with main (9311390)2

Open in CodSpeed

Footnotes

  1. 472 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 (276ffe9) during the generation of this report, so 9311390 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Comment thread tests/by-util/test_cp.rs Resolved
Comment thread src/uu/cp/src/cp.rs Resolved
Comment thread tests/by-util/test_cp.rs Resolved
Comment thread tests/by-util/test_cp.rs Resolved
Making the backup by copying reads the destination. On Windows that fails when
the destination is a running image, which can be renamed but neither deleted
nor overwritten in place, so cp --backup could not replace an executable that
is in use. Move the destination aside instead, as GNU's backup_file_rename does.

cp FILE FILE still copies, since moving the destination aside there would take
the source with it. The same holds when the two names differ only in case on a
case-insensitive filesystem, where they name one file: compare the source and
the destination as directory entries rather than byte for byte, and leave the
file alone when it is the source itself.

Fixes uutils#3034
@Smicry
Smicry force-pushed the fix/cp-backup-open-exe branch from 15819b3 to 58d404d Compare November 20, 2026 18:04

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 with backup is not able to replace an open .exe file

2 participants