@@ -393,11 +393,12 @@ async fn download_package_manager(
393393 create_shim_files ( package_manager_type, & bin_prefix) . await ?;
394394 Ok ( install_dir)
395395 }
396- Err ( e) if is_already_exists_error ( & e ) => {
396+ Err ( e) if e . kind ( ) == std :: io :: ErrorKind :: AlreadyExists => {
397397 // Another concurrent process created the directory - that's OK
398398 tracing:: debug!( "Target directory already exists (concurrent creation), using it" ) ;
399399 // Clean up the temporary directory we don't need anymore
400- if let Err ( cleanup_err) = remove_dir_all ( & target_dir_tmp) . await {
400+ // Use remove_dir_all_force to handle potential concurrent cleanup attempts
401+ if let Err ( cleanup_err) = remove_dir_all_force ( & target_dir_tmp) . await {
401402 tracing:: warn!(
402403 "Failed to clean up temporary directory {:?}: {}" ,
403404 target_dir_tmp,
@@ -415,8 +416,6 @@ async fn download_package_manager(
415416const ENOTEMPTY_LINUX : i32 = 39 ; // Directory not empty on Linux
416417const ENOTEMPTY_BSD : i32 = 66 ; // Directory not empty on macOS/BSD
417418const ERROR_DIR_NOT_EMPTY_WINDOWS : i32 = 145 ; // Directory not empty on Windows
418- const EEXIST_UNIX : i32 = 17 ; // File exists on Unix (both Linux and macOS)
419- const ERROR_ALREADY_EXISTS_WINDOWS : i32 = 183 ; // File/directory already exists on Windows
420419
421420/// Remove the directory and all its contents.
422421/// Ignore the error if the directory is not found or already being removed by another process.
@@ -442,15 +441,6 @@ async fn remove_dir_all_force(path: impl AsRef<Path>) -> Result<(), std::io::Err
442441 }
443442}
444443
445- /// Check if an error indicates that a file or directory already exists.
446- fn is_already_exists_error ( e : & std:: io:: Error ) -> bool {
447- e. kind ( ) == std:: io:: ErrorKind :: AlreadyExists
448- || matches ! (
449- e. raw_os_error( ) ,
450- Some ( EEXIST_UNIX ) | Some ( ERROR_ALREADY_EXISTS_WINDOWS )
451- )
452- }
453-
454444/// Create shim files for the package manager.
455445///
456446/// Will automatically create `{cli_name}.cjs`, `{cli_name}.cmd`, `{cli_name}.ps1` files for the package manager.
0 commit comments