Skip to content

Commit 41eb8f9

Browse files
committed
config: Fix over-reinstallation bug
When we check if an overridden toolchain has everything it needs, we sometimes decided to reinstall despite everything being present. This reworks the decision-making to take into account rewritten component names, and also to handle targets properly. Signed-off-by: Daniel Silverstone <[email protected]>
1 parent ea80979 commit 41eb8f9

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
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
}

0 commit comments

Comments
 (0)