Skip to content

Commit dda6ab8

Browse files
Fix typos and improve Windows symlink handling in lib.rs
- Corrected a typo in the error message from "Couldn’t" to "Couldn't". - Enhanced the logic for removing symlinks on Windows to handle invalid targets more gracefully by attempting to remove them as files before falling back to directory removal. r? `@ghost`
1 parent bc4376f commit dda6ab8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/bootstrap/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl Build {
408408
.strip_prefix(&config.initial_sysroot)
409409
.unwrap_or_else(|_| {
410410
panic!(
411-
"Couldnt resolve the initial relative libdir from {}",
411+
"Couldn't resolve the initial relative libdir from {}",
412412
initial_target_dir.display()
413413
)
414414
})
@@ -543,7 +543,17 @@ impl Build {
543543
// Left over from a previous build; overwrite it.
544544
// This matters if `build.build` has changed between invocations.
545545
#[cfg(windows)]
546-
t!(fs::remove_dir(&host));
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+
}
547557
#[cfg(not(windows))]
548558
t!(fs::remove_file(&host));
549559
}

0 commit comments

Comments
 (0)