Make mv command fallback to copy only if the src and dst are on different device#6040
Make mv command fallback to copy only if the src and dst are on different device#6040sylvestre merged 1 commit intouutils:mainfrom
Conversation
c06329e to
c3c4cef
Compare
|
Thanks for putting this up! I have two questions reading this that I think we need to answer before merging this.
|
src/uu/mv/Cargo.toml
Outdated
There was a problem hiding this comment.
can we do it with winapi_util?
I am a bit reluctant to add a new dep
There was a problem hiding this comment.
winapi_util seems like no ERROR_NOT_SAME_DEVICE. maybe i can use windows-sys?
|
GNU testsuite comparison: |
|
f768b41 to
b20c9a5
Compare
|
GNU testsuite comparison: |
|
Two jobs are failing. Minor stuff :) |
a861732 to
5b4c5ee
Compare
|
GNU testsuite comparison: |
|
@sylvestre i have fixed cSpell and
but it does not seem to be caused my changes. |
|
GNU testsuite comparison: |
sorry but it is very very likely your change here |
|
@sylvestre Thanks for your patience. I have found the problem, the call to But I don't think it's my fault, because the GNU tests running Before my changes, the GNU tests passed, but the result is incorrect. see the outputs below: I have created a new branch to try to fix this problem: #6119. The outputs after this change: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
What needs to be done to get this PR merged? |
|
I think @jfinkels has been upgrading your PR :) |
|
This change adds a Windows-specific check that explicitly removes the destination file before attempting to rename/move the source file. This is needed because on Windows, if the source file is opened (even with FILE_SHARE_DELETE) and the destination file exists, the MoveFileExW operation will fail with "Access Denied". By removing the destination file first, we ensure the move operation can succeed. fn rename_with_fallback(
from: &Path,
to: &Path,
multi_progress: Option<&MultiProgress>,
) -> io::Result<()> {
#[cfg(windows)]
if to.is_file() {
// On Windows, if the source file is opened (even with FILE_SHARE_DELETE) and
// the destination file exists, MoveFileExW will fail with "Access Denied".
// We need to explicitly remove the destination file first to make the move operation succeed.
fs::remove_file(to)?;
}
// ...
} |
|
GNU testsuite comparison: |
09b9fe0 to
b1a7b67
Compare
|
GNU testsuite comparison: |
|
I adjusted the solution by removing the deletion logic before rename (which could lead to scenarios where the file move fails but the target file is deleted). Instead, it now directly falls back to the copy logic. However, to avoid situations where copy operations might fail due to lacking delete permissions on the source file, we added the |
|
@sylvestre ready for review |
|
Thanks and well done :) |
fixes #6029