Skip to content

Commit 656d396

Browse files
authored
Merge pull request #2573 from kinnison/toolchain-reinstalling-fix-2571
Toolchain reinstalling fix 2571
2 parents 1350d9e + 41eb8f9 commit 656d396

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/config.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,17 +625,37 @@ impl Cfg {
625625
targets: &[&str],
626626
) -> Result<bool> {
627627
let components_requested = !components.is_empty() || !targets.is_empty();
628-
628+
// If we're here, the toolchain exists on disk and is a dist toolchain
629+
// so we should attempt to load its manifest
630+
let manifest = if let Some(manifest) = distributable.get_manifest()? {
631+
manifest
632+
} else {
633+
// If we can't read the manifest we'd best try and install
634+
return Ok(true);
635+
};
629636
match (distributable.list_components(), components_requested) {
630637
// If the toolchain does not support components but there were components requested, bubble up the error
631638
(Err(e), true) => Err(e),
632-
(Ok(installed_components), _) => {
633-
Ok(components.iter().chain(targets.iter()).all(|name| {
634-
installed_components.iter().any(|status| {
635-
status.component.short_name_in_manifest() == name && status.installed
639+
// Otherwise check if all the components we want are installed
640+
(Ok(installed_components), _) => Ok(components.iter().all(|name| {
641+
installed_components.iter().any(|status| {
642+
let cname = status.component.short_name(&manifest);
643+
let cname = cname.as_str();
644+
let cnameim = status.component.short_name_in_manifest();
645+
let cnameim = cnameim.as_str();
646+
(cname == *name || cnameim == *name) && status.installed
647+
})
648+
})
649+
// And that all the targets we want are installed
650+
&& targets.iter().all(|name| {
651+
installed_components
652+
.iter()
653+
.filter(|c| c.component.short_name_in_manifest() == "rust-std")
654+
.any(|status| {
655+
let ctarg = status.component.target();
656+
(ctarg == *name) && status.installed
636657
})
637-
}))
638-
}
658+
})),
639659
_ => Ok(true),
640660
}
641661
}

src/toolchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ impl<'a> DistributableToolchain<'a> {
664664
}
665665

666666
// Installed only.
667-
fn get_manifest(&self) -> Result<Option<Manifest>> {
667+
pub fn get_manifest(&self) -> Result<Option<Manifest>> {
668668
if !self.0.exists() {
669669
return Err(ErrorKind::ToolchainNotInstalled(self.0.name().to_owned()).into());
670670
}

0 commit comments

Comments
 (0)