mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-10-26 01:34:51 +08:00
fix(windows): fall back when WSL rejects atomic replace (#6232)
* fix(windows): fall back when WSL rejects atomic replace * fix(windows): preserve config during WSL fallback * fix(windows): use rename fallback for WSL UNC
This commit is contained in:
1 parent
413c09e079
commit
c39c90322a
1 file changed
+8
-2
@@ -386,7 +386,9 @@ pub fn atomic_write(path: &Path, data: &[u8]) -> Result<(), AppError> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use windows_sys::Win32::Storage::FileSystem::ReplaceFileW;
|
||||
use windows_sys::Win32::{
|
||||
Foundation::ERROR_NOT_SUPPORTED, Storage::FileSystem::ReplaceFileW,
|
||||
};
|
||||
|
||||
let replaced: Vec<u16> = path
|
||||
.as_os_str()
|
||||
@@ -420,7 +422,11 @@ pub fn atomic_write(path: &Path, data: &[u8]) -> Result<(), AppError> {
|
||||
}
|
||||
|
||||
let replace_error = std::io::Error::last_os_error();
|
||||
if replace_error.kind() != std::io::ErrorKind::NotFound {
|
||||
// WSL UNC paths reject ReplaceFileW with ERROR_NOT_SUPPORTED (50).
|
||||
// std::fs::rename uses a different replace-existing API on Windows.
|
||||
let replace_not_supported =
|
||||
replace_error.raw_os_error() == Some(ERROR_NOT_SUPPORTED as i32);
|
||||
if replace_error.kind() != std::io::ErrorKind::NotFound && !replace_not_supported {
|
||||
last_error = Some(replace_error);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user