Skip to content

Commit 2c4af24

Browse files
Refactor Windows symlink removal logic in lib.rs
- Simplified the handling of symlinks on Windows by removing the fallback to directory removal. The `fs::remove_file` function now directly handles both file and directory symlinks, even when the target is invalid, improving code clarity and reliability.
1 parent d7eeb7d commit 2c4af24

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/bootstrap/src/lib.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -542,19 +542,8 @@ impl Build {
542542
if host.is_symlink() {
543543
// Left over from a previous build; overwrite it.
544544
// This matters if `build.build` has changed between invocations.
545-
#[cfg(windows)]
546-
{
547-
// On Windows, symlinks (including junctions) can fail to be removed with
548-
// `fs::remove_dir` if the target is invalid, causing error 267
549-
// "The directory name is invalid". This can happen when the symlink
550-
// points to a non-existent or corrupted target.
551-
// We try removing as a file first (works for invalid symlinks),
552-
// then fall back to removing as a directory if needed.
553-
if let Err(_) = fs::remove_file(&host) {
554-
t!(fs::remove_dir(&host));
555-
}
556-
}
557-
#[cfg(not(windows))]
545+
// On Windows, `fs::remove_file` can remove both file and directory symlinks/junctions,
546+
// even when the target is invalid (which causes error 267 with `fs::remove_dir`).
558547
t!(fs::remove_file(&host));
559548
}
560549
t!(

0 commit comments

Comments
 (0)