Skip to content

Commit 07db9ed

Browse files
committed
refactor: remove redundant try_exists guard, add debug log
- Remove redundant try_exists check before remove_or_rename_to_old since it already handles NotFound - Log the original remove_file error at debug level before falling back to rename
1 parent 6cbdab5 commit 07db9ed

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,7 @@ async fn create_package_shim(
409409
let shim_path = bin_dir.join(format!("{}.exe", bin_name));
410410

411411
// Delete before overwrite; falls back to rename if the exe is locked.
412-
if tokio::fs::try_exists(&shim_path).await.unwrap_or(false) {
413-
super::setup::remove_or_rename_to_old(&shim_path).await;
414-
}
412+
super::setup::remove_or_rename_to_old(&shim_path).await;
415413

416414
// Copy the trampoline binary as <bin_name>.exe.
417415
// The trampoline detects the tool name from its own filename and sets

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,10 @@ pub(crate) async fn remove_or_rename_to_old(path: &vite_path::AbsolutePath) {
362362
match tokio::fs::remove_file(path).await {
363363
Ok(()) => return,
364364
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return,
365-
Err(_) => {}
365+
Err(e) => {
366+
tracing::debug!("remove_file failed ({}), attempting rename", e);
367+
}
366368
}
367-
// File exists but is locked (e.g., running process) — rename instead.
368369
rename_to_old(path).await;
369370
}
370371

0 commit comments

Comments
 (0)