-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
base: master
Are you sure you want to change the base?
Fix Windows bootstrap panic on invalid symlink removal (issue #143045) #143052
Conversation
rustbot has assigned @albertlarsan68. Use |
@hasip-timurtas Please make your PR description concise so your reviewer does not waste time reading it. It should only need to be about two sentences for a change of this size. |
Oh, your original commit message contains That's something for guiding rustbot. You need to put it in your PR description for it to work. I can help, though, by unassigning your reviewer, since r? @ghost is for a PR that you do not intend to have reviewed. |
Failed to set assignee to
|
@workingjubilee please check if it's ok now 🙂 |
@hasip-timurtas Yes, that looks good to me. You may want to remove the |
dda6ab8
to
baa9fcf
Compare
- 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.
baa9fcf
to
d7eeb7d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is incorrect and I also don't think the code is the correct fix. Both remove_file
and remove_dir
can remove symlinks. However, remove_dir
can only remove directory symlinks.
- 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.
@ChrisDenton Thank you for the feedback After digging into the Windows implementation, I found that This is why it works on invalid symlinks - it doesn't try to follow them. Since |
@rustbot ready |
Sorry, I think you've misunderstood what that code is doing. Both On Windows there are two types of symlink: directory and non-directory. So I would prefer this be implemented something like: if |
- Updated the symlink removal process on Windows to first attempt removing directory symlinks with `fs::remove_dir`, and fallback to `fs::remove_file` for file symlinks. This change improves error handling and clarity in the code.
@ChrisDenton Thank you for the clarification. I've implemented your suggested approach, but I'd like to confirm a few details to ensure we're handling all scenarios correctly:
The current implementation: 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);
}
} I want to make sure we're covering all the edge cases for this Windows-specific issue. |
This comment has been minimized.
This comment has been minimized.
- Changed the error message in the symlink removal logic to use the more concise formatting syntax `{e}` instead of the longer `format!` style. This improves readability and maintains consistency in error handling.
Fix Windows bootstrap panic on invalid symlink removal (issue #143045)
On Windows, use
fs::remove_file
for symlinks instead offs::remove_dir
to avoid error 267 when the symlink target is invalid.fs::remove_file
can handle both file and directory symlinks/junctions, even when their targets don't exist.r? @ghost