Skip to content

Commit fb000ed

Browse files
committed
correctly uninstall toolchains that are stale symlinks
1 parent 001c71e commit fb000ed

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/rustup/toolchain.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ impl<'a> Toolchain<'a> {
6868
pub fn path(&self) -> &Path {
6969
&self.path
7070
}
71+
fn is_symlink(&self) -> bool {
72+
use std::fs;
73+
fs::symlink_metadata(&self.path).map(|m| m.file_type().is_symlink()).unwrap_or(false)
74+
}
7175
pub fn exists(&self) -> bool {
7276
// HACK: linked toolchains are symlinks, and, contrary to what std docs
7377
// lead me to believe `fs::metadata`, used by `is_directory` does not
7478
// seem to follow symlinks on windows.
7579
let is_symlink = if cfg!(windows) {
76-
use std::fs;
77-
fs::symlink_metadata(&self.path).map(|m| m.file_type().is_symlink()).unwrap_or(false)
80+
self.is_symlink()
7881
} else {
7982
false
8083
};
@@ -84,7 +87,7 @@ impl<'a> Toolchain<'a> {
8487
Ok(try!(utils::assert_is_directory(&self.path)))
8588
}
8689
pub fn remove(&self) -> Result<()> {
87-
if self.exists() {
90+
if self.exists() || self.is_symlink() {
8891
(self.cfg.notify_handler)(Notification::UninstallingToolchain(&self.name));
8992
} else {
9093
(self.cfg.notify_handler)(Notification::ToolchainNotInstalled(&self.name));

0 commit comments

Comments
 (0)