Skip to content

Commit ec2e522

Browse files
seritoolsmbilker
authored andcommitted
Add fallback implementation for MoveFileExW
Falls back to calls to `CopyFileW` and `DeleteFile`.
1 parent ea62d85 commit ec2e522

File tree

1 file changed

+16
-2
lines changed
  • library/std/src/sys/windows

1 file changed

+16
-2
lines changed

library/std/src/sys/windows/fs.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,22 @@ pub fn unlink(p: &Path) -> io::Result<()> {
11261126
pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
11271127
let old = maybe_verbatim(old)?;
11281128
let new = maybe_verbatim(new)?;
1129-
cvt(unsafe { c::MoveFileExW(old.as_ptr(), new.as_ptr(), c::MOVEFILE_REPLACE_EXISTING) })?;
1130-
Ok(())
1129+
let res =
1130+
cvt(unsafe { c::MoveFileExW(old.as_ptr(), new.as_ptr(), c::MOVEFILE_REPLACE_EXISTING) });
1131+
1132+
match res {
1133+
Err(ref e) if e.raw_os_error() == Some(c::ERROR_CALL_NOT_IMPLEMENTED as i32) => {
1134+
// 9x/ME doesn't support MoveFileEx, so we fall back to copy + delete and hope for the
1135+
// best
1136+
unsafe {
1137+
cvt(c::CopyFileW(old.as_ptr(), new.as_ptr(), c::TRUE))?;
1138+
cvt(c::DeleteFileW(old.as_ptr()))?;
1139+
Ok(())
1140+
}
1141+
}
1142+
Err(e) => Err(e),
1143+
Ok(_) => Ok(()),
1144+
}
11311145
}
11321146

11331147
pub fn rmdir(p: &Path) -> io::Result<()> {

0 commit comments

Comments
 (0)