Skip to content

Commit 334b9a9

Browse files
committed
fix(env): handle NotFound in remove_or_rename_to_old
Address PR review: explicitly check for NotFound when trying to delete an .exe file, returning early instead of falling through to the rename_to_old fallback. Closes #1349
1 parent 9cd9a20 commit 334b9a9

File tree

1 file changed

+5
-2
lines changed
  • crates/vite_global_cli/src/commands/env

1 file changed

+5
-2
lines changed

crates/vite_global_cli/src/commands/env/setup.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,12 @@ pub(crate) fn get_trampoline_path() -> Result<vite_path::AbsolutePathBuf, Error>
359359
/// This avoids accumulating `.old` files when the exe is not in use.
360360
#[cfg(windows)]
361361
pub(crate) async fn remove_or_rename_to_old(path: &vite_path::AbsolutePath) {
362-
if tokio::fs::remove_file(path).await.is_ok() {
363-
return;
362+
match tokio::fs::remove_file(path).await {
363+
Ok(()) => return,
364+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return,
365+
Err(_) => {}
364366
}
367+
// File exists but is locked (e.g., running process) — rename instead.
365368
rename_to_old(path).await;
366369
}
367370

0 commit comments

Comments
 (0)