cp: force mode: try to open destination for write to check if delete is required
So far cp only checked if the metadata of the destination file indicates read-only permissions. In order to handle the case where the destination file is in use, we try to open the destination file for writing. Also other cases which prevent overwriting can be detected that way.
For the test case we copy the coreutils binary to a test directory. Then use the copy to try to copy a file over itself. This should fail in non-force mode, but succeed in force mode.
this fixes https://github.com/uutils/coreutils/issues/8261
GNU testsuite comparison:
GNU test failed: tests/cp/special-f. tests/cp/special-f is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
ok, this does not work (related GNU test fails). I'll further investigate.
GNU testsuite comparison:
Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
@sylvestre thank you for your review. I addressed the findings. Please check.
fails here:
---- test_cp::test_cp_dest_in_use stdout ----
bin: "/home/runner.linux/work/target/debug/coreutils"
thread 'test_cp::test_cp_dest_in_use' panicked at tests/by-util/test_cp.rs:6895:10:
Failed to execute command: Os { code: 26, kind: ExecutableFileBusy, message: "Text file busy" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
test_cp::test_cp_dest_in_use
test result: FAILED. 3810 passed; 1 failed; 40 ignored; 0 measured; 0 filtered out; finished in 77.11s
GNU testsuite comparison:
GNU test failed: tests/cp/cross-dev-symlink. tests/cp/cross-dev-symlink is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)
ok, this needs more investigations. I'll change the PR back to draft.