Skip to content

Commit 00829c6

Browse files
committed
fix(settings): remove overrides set on a path before it became a symlink
Overrides are keyed by canonical path, so `rustup override unset --path` resolved a symlink and removed the override of its target instead. An override set on the path before it was turned into a symlink stayed behind, with no way to remove it (rust-lang#1138). `Settings::remove_override()` now first tries the key of the path itself, i.e. its canonical parent joined with its file name, and only falls back to the resolved path when there is no such override.
1 parent 7d2a751 commit 00829c6

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎src/settings.rs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{
22
cell::RefCell,
33
collections::BTreeMap,
44
fmt,
5-
path::{Path, PathBuf},
5+
path::{Path, PathBuf, absolute},
66
str::FromStr,
77
};
88

@@ -113,6 +113,17 @@ impl Settings {
113113
}
114114

115115
pub(crate) fn remove_override(&mut self, path: &Path) -> bool {
116+
// `path_to_key()` resolves symlinks, but `path` might have only become a
117+
// symlink after its override was set, leaving that override keyed by
118+
// `path` itself. Remove it first rather than the override of the target.
119+
let unresolved_key = absolute(path).ok().and_then(|abs_path| {
120+
let parent = abs_path.parent()?.canonicalize().ok()?;
121+
Some(parent.join(abs_path.file_name()?).display().to_string())
122+
});
123+
if unresolved_key.is_some_and(|key| self.overrides.remove(&key).is_some()) {
124+
return true;
125+
}
126+
116127
let key = Self::path_to_key(path);
117128
self.overrides.remove(&key).is_some()
118129
}

‎tests/suite/cli_exact.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ info: override toolchain for '[PATH]' removed
530530
.extend_redactions([("[OLD]", old), ("[NEW]", new)])
531531
.is_ok()
532532
.with_stdout(snapbox::str![[r#"
533-
[OLD] nightly
533+
[NEW] nightly
534534
535535
"#]])
536536
.with_stderr(snapbox::str![[""]]);

0 commit comments

Comments
 (0)