Skip to content

Commit 6c33197

Browse files
authored
Merge pull request #2897 from sathwikmatsa/remove-trailing-slash
Remove trailing slashes in toolchain name
2 parents 3800e63 + 3f3e0af commit 6c33197

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,11 +1003,13 @@ impl Cfg {
10031003
}
10041004

10051005
pub(crate) fn resolve_toolchain(&self, name: &str) -> Result<String> {
1006-
if let Ok(desc) = dist::PartialToolchainDesc::from_str(name) {
1006+
// remove trailing slashes in toolchain name
1007+
let normalized_name = name.trim_end_matches('/');
1008+
if let Ok(desc) = dist::PartialToolchainDesc::from_str(normalized_name) {
10071009
let host = self.get_default_host_triple()?;
10081010
Ok(desc.resolve(&host)?.to_string())
10091011
} else {
1010-
Ok(name.to_owned())
1012+
Ok(normalized_name.to_owned())
10111013
}
10121014
}
10131015
}

tests/cli-v2.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,32 @@ fn remove_toolchain() {
212212
});
213213
}
214214

215+
// Issue #2873
216+
#[test]
217+
fn remove_toolchain_ignore_trailing_slash() {
218+
setup(&|config| {
219+
// custom toolchain name with trailing slash
220+
let path = config.customdir.join("custom-1");
221+
let path_str = path.to_string_lossy();
222+
expect_ok(config, &["rustup", "toolchain", "link", "dev", &path_str]);
223+
expect_stderr_ok(
224+
config,
225+
&["rustup", "toolchain", "remove", "dev/"],
226+
"toolchain 'dev' uninstalled",
227+
);
228+
// check if custom toolchain directory contents are not removed
229+
let toolchain_dir_is_non_empty = fs::read_dir(&path).unwrap().next().is_some();
230+
assert!(toolchain_dir_is_non_empty);
231+
// distributable toolchain name with trailing slash
232+
expect_ok(config, &["rustup", "update", "nightly"]);
233+
expect_stderr_ok(
234+
config,
235+
&["rustup", "toolchain", "remove", for_host!("nightly-{}/")],
236+
for_host!("toolchain 'nightly-{}' uninstalled"),
237+
);
238+
});
239+
}
240+
215241
#[test]
216242
fn add_remove_multiple_toolchains() {
217243
fn go(add: &str, rm: &str) {

0 commit comments

Comments
 (0)