Repository navigation
cp: put the backup back when the copy fails after making it - #16320
draarivpatel-ui wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
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.
|
The CICD workflow runs are gated behind maintainer approval for first-time contributors ( |
|
|
||
| #[test] | ||
| #[cfg(unix)] | ||
| #[cfg_attr(wasi_runner, ignore = "WASI: no chmod syscall")] |
There was a problem hiding this comment.
I don't see a chmod here.
| fs::copy(backup_path, dest).map(|_| ()) | ||
| }; | ||
|
|
||
| if let Err(err) = restore { |
There was a problem hiding this comment.
/// Restore the backup after a failed copy, matching GNU cp semantics.
fn restore_backup(dest: &Path, backup_path: &Path, was_dest_symlink: bool) {
// Best-effort restoration; the original copy error is reported.
if was_dest_symlink {
let _ = fs::rename(backup_path, dest);
} else {
let _ = fs::copy(backup_path, dest);
}
}There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
thanks for this PR! also, can you make it smaller ? it is a too large diff |
|
Thanks for the review. Both inline comments and the pre-push findings are addressed in the updated branch. On On On Windows: the progress callback declares Verification: 6 package tests and 361 cp integration tests pass with zero failures. Clippy with warnings denied and formatting checks pass, including Windows target checks on x86_64 and aarch64. The patch applies cleanly to current upstream main. |
99d3116 to
8b3c9e9
Compare
There was a problem hiding this comment.
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.
|
Binary size comparison: |
8b3c9e9 to
3d0e841
Compare
There was a problem hiding this comment.
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.
Signed-off-by: draarivpatel-ui <287273626+draarivpatel-ui@users.noreply.github.com>
3d0e841 to
295c0a7
Compare
There was a problem hiding this comment.
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.
Use relative symlinks in test_cp_backup_restore_preserves_destination_symlink so the destination link target resolves inside the WASI preopened directory instead of appearing dangling. Place #[uutests::wasi_ignore(NoPermissionBits)] before #[test] on the permission-dependent backup restore tests so the proc macro attaches the ignore attribute before the test harness expands #[test]. Signed-off-by: draarivpatel-ui <287273626+draarivpatel-ui@users.noreply.github.com>
There was a problem hiding this comment.
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.
|
GNU testsuite comparison: |
There was a problem hiding this comment.
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.
Merging this PR will regress 3 benchmarks3 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Fixes #16240
Summary
With
--backup, cp backs up the destination and then copies. If the copy fails after the backup was made, GNU 9.12 puts the backup back in place ofdest, so the destination is left as it was before the attempt. uutils kept the backup atdest~and leftdestmissing or truncated:Fix
copy_filenow checks whether a backup file exists afterhandle_existing_destran, and whenhandle_copy_modefails, it restores the backup ontodestbefore returning the error:fs::renamewhen the backup was a renamed symlink destination,fs::copyfor a regular-file backup. Restoring is best-effort; the original copy error is still what gets reported.The same failure modes the issue describes are covered: any failure inside
handle_copy_mode(source open, destination create, stream copy) after the backup.Testing
test_cp_backup_restored_when_copy_fails: a--forcecopy from an unreadable source fails after the backup;destanddest~must both hold the original content.test_cp_backup_restored_when_source_cannot_be_statted: the source disappears between the backup and the stat;destis restored fromdest~.cargo test --features cp: 5261 passed, 25 ignored, 0 failed.