Skip to content

Fix Windows bootstrap panic on invalid symlink removal (issue #143045) #143052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl Build {
.strip_prefix(&config.initial_sysroot)
.unwrap_or_else(|_| {
panic!(
"Couldnt resolve the initial relative libdir from {}",
"Couldn't resolve the initial relative libdir from {}",
initial_target_dir.display()
)
})
Expand Down Expand Up @@ -542,10 +542,16 @@ impl Build {
if host.is_symlink() {
// Left over from a previous build; overwrite it.
// This matters if `build.build` has changed between invocations.
#[cfg(windows)]
t!(fs::remove_dir(&host));
#[cfg(not(windows))]
t!(fs::remove_file(&host));
// Try remove_dir first (for directory symlinks), then remove_file (for file symlinks).
// On Windows, there are two types of symlinks: directory and file symlinks.
// remove_dir only works on directory symlinks, remove_file only works on file symlinks.
if let Err(e) = fs::remove_dir(&host) {
if e.kind() == io::ErrorKind::NotADirectory {
t!(fs::remove_file(&host));
} else {
panic!("failed to remove symlink: {e}");
}
}
}
t!(
symlink_dir(&build.config, &build_triple, &host),
Expand Down
Loading