@@ -22,6 +22,8 @@ use vite_install::request::HttpClient;
2222use vite_path:: AbsolutePathBuf ;
2323use vite_setup:: { install, integrity, platform, registry} ;
2424
25+ const VP_BINARY_NAME : & str = if cfg ! ( windows) { "vp.exe" } else { "vp" } ;
26+
2527/// Restrict DLL search to system32 only to prevent DLL hijacking
2628/// when the installer is run from a Downloads folder.
2729#[ cfg( windows) ]
@@ -141,8 +143,7 @@ async fn do_install(
141143 }
142144 install:: extract_platform_package ( & platform_data, & version_dir) . await ?;
143145
144- let binary_name = if cfg ! ( windows) { "vp.exe" } else { "vp" } ;
145- let binary_path = version_dir. join ( "bin" ) . join ( binary_name) ;
146+ let binary_path = version_dir. join ( "bin" ) . join ( VP_BINARY_NAME ) ;
146147 if !tokio:: fs:: try_exists ( & binary_path) . await . unwrap_or ( false ) {
147148 return Err ( "Binary not found after extraction. The download may be corrupted." . into ( ) ) ;
148149 }
@@ -193,31 +194,26 @@ async fn do_install(
193194 Ok ( ( ) )
194195}
195196
196- /// On Windows, rename a running exe to `.old` then copy the new one in place .
197+ /// Windows locks running `.exe` files — rename the old one out of the way before copying .
197198#[ cfg( windows) ]
198199async fn replace_windows_exe (
199200 src : & vite_path:: AbsolutePathBuf ,
200201 dst : & vite_path:: AbsolutePathBuf ,
201202 bin_dir : & vite_path:: AbsolutePathBuf ,
202203) -> Result < ( ) , Box < dyn std:: error:: Error > > {
203- if dst. as_path ( ) . exists ( ) {
204- let old_name = format ! (
205- "vp.exe.{}.old" ,
206- std:: time:: SystemTime :: now( )
207- . duration_since( std:: time:: UNIX_EPOCH )
208- . unwrap_or_default( )
209- . as_secs( )
210- ) ;
211- let _ = tokio:: fs:: rename ( dst, & bin_dir. join ( & old_name) ) . await ;
212- }
204+ let old_name = format ! (
205+ "vp.exe.{}.old" ,
206+ std:: time:: SystemTime :: now( )
207+ . duration_since( std:: time:: UNIX_EPOCH )
208+ . unwrap_or_default( )
209+ . as_secs( )
210+ ) ;
211+ let _ = tokio:: fs:: rename ( dst, & bin_dir. join ( & old_name) ) . await ;
213212 tokio:: fs:: copy ( src, dst) . await ?;
214213 Ok ( ( ) )
215214}
216215
217- /// Set up the bin/ directory with the initial `vp` shim.
218- ///
219- /// On Windows, copies `vp-shim.exe` from `current/bin/` to `bin/vp.exe`.
220- /// On Unix, creates a symlink from `bin/vp` to `../current/bin/vp`.
216+ /// Set up the `bin/vp` entry point (trampoline copy on Windows, symlink on Unix).
221217async fn setup_bin_shims (
222218 install_dir : & vite_path:: AbsolutePath ,
223219) -> Result < ( ) , Box < dyn std:: error:: Error > > {
@@ -284,10 +280,8 @@ async fn download_with_progress(
284280 Ok ( data)
285281}
286282
287- /// Create shell env files by spawning `vp env setup --env-only`.
288283async fn create_env_files ( install_dir : & vite_path:: AbsolutePath ) {
289- let vp_binary =
290- install_dir. join ( "current" ) . join ( "bin" ) . join ( if cfg ! ( windows) { "vp.exe" } else { "vp" } ) ;
284+ let vp_binary = install_dir. join ( "current" ) . join ( "bin" ) . join ( VP_BINARY_NAME ) ;
291285
292286 if !tokio:: fs:: try_exists ( & vp_binary) . await . unwrap_or ( false ) {
293287 return ;
0 commit comments