Skip to content

Commit 973b6e9

Browse files
CopilotBrooooooklyn
andcommitted
Use ErrorKind::DirectoryNotEmpty for cross-platform compatibility
Replace OS-specific error codes with standard ErrorKind for better maintainability Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
1 parent e5a880b commit 973b6e9

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

crates/vite_install/src/package_manager.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,6 @@ async fn download_package_manager(
411411
}
412412
}
413413

414-
// OS-specific error codes for concurrent file system operations
415-
// Note: ENOTEMPTY varies by Unix flavor - Linux uses 39, macOS/BSD use 66
416-
const ENOTEMPTY_LINUX: i32 = 39; // Directory not empty on Linux
417-
const ENOTEMPTY_BSD: i32 = 66; // Directory not empty on macOS/BSD
418-
const ERROR_DIR_NOT_EMPTY_WINDOWS: i32 = 145; // Directory not empty on Windows
419-
420414
/// Remove the directory and all its contents.
421415
/// Ignore the error if the directory is not found or already being removed by another process.
422416
async fn remove_dir_all_force(path: impl AsRef<Path>) -> Result<(), std::io::Error> {
@@ -426,12 +420,11 @@ async fn remove_dir_all_force(path: impl AsRef<Path>) -> Result<(), std::io::Err
426420
// Ignore errors that can occur during concurrent test execution:
427421
// - NotFound: directory was already removed
428422
// - DirectoryNotEmpty: another process is actively using/removing the directory
429-
if e.kind() == std::io::ErrorKind::NotFound
430-
|| matches!(
431-
e.raw_os_error(),
432-
Some(ENOTEMPTY_LINUX) | Some(ENOTEMPTY_BSD) | Some(ERROR_DIR_NOT_EMPTY_WINDOWS)
433-
)
434-
{
423+
// Using ErrorKind for cross-platform compatibility instead of raw OS error codes
424+
if matches!(
425+
e.kind(),
426+
std::io::ErrorKind::NotFound | std::io::ErrorKind::DirectoryNotEmpty
427+
) {
435428
tracing::debug!("Ignoring directory removal error (likely concurrent access): {}", e);
436429
Ok(())
437430
} else {

0 commit comments

Comments
 (0)