From c39c90322a052d5d738e52286691228208e18ccb Mon Sep 17 00:00:00 2001 From: Allen Xu Date: Mon, 10 Aug 2026 11:29:12 +0800 Subject: [PATCH] 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 --- src-tauri/src/config.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index b8ed31004..b77e53296 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -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 = 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; }