Skip to content

Commit 992ab57

Browse files
committed
override: Detect v1 manifests and do not reinstall if found
When we're installing a toolchain via the override mechanism we try and ensure components requested are present. This is a no-op on v1 manifest installations but we still end up downloading and checking the update hash. This is unnecessary, so this change attempts to prevent this by detecting a V1 install and skipping the component check if so. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
1 parent 3a25ac6 commit 992ab57

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,10 @@ impl Cfg {
715715
let manifest = if let Some(manifest) = distributable.get_manifest()? {
716716
manifest
717717
} else {
718-
// If we can't read the manifest we'd best try and install
719-
return Ok(false);
718+
// We can't read the manifest. If this is a v1 install that's understandable
719+
// and we assume the components are all good, otherwise we need to have a go
720+
// at re-fetching the manifest to try again.
721+
return Ok(distributable.guess_v1_manifest());
720722
};
721723
match (distributable.list_components(), components_requested) {
722724
// If the toolchain does not support components but there were components requested, bubble up the error

src/toolchain.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub enum UpdateStatus {
6464
Unchanged,
6565
}
6666

67+
static V1_COMMON_COMPONENT_LIST: &[&str] = &["cargo", "rustc", "rust-docs"];
68+
6769
impl<'a> Toolchain<'a> {
6870
pub fn from(cfg: &'a Cfg, name: &str) -> Result<Self> {
6971
let resolved_name = cfg.resolve_toolchain(name)?;
@@ -953,6 +955,23 @@ impl<'a> DistributableToolchain<'a> {
953955
fn update_hash(&self) -> Result<PathBuf> {
954956
self.0.cfg.get_hash_file(&self.0.name, true)
955957
}
958+
959+
// Installed only.
960+
pub fn guess_v1_manifest(&self) -> bool {
961+
let prefix = InstallPrefix::from(self.0.path().to_owned());
962+
// If all the v1 common components are present this is likely to be
963+
// a v1 manifest install. The v1 components are not called the same
964+
// in a v2 install.
965+
for component in V1_COMMON_COMPONENT_LIST {
966+
let manifest = format!("manifest-{}", component);
967+
let manifest_path = prefix.manifest_file(&manifest);
968+
if !utils::path_exists(manifest_path) {
969+
return false;
970+
}
971+
}
972+
// It's reasonable to assume this is a v1 manifest installation
973+
true
974+
}
956975
}
957976

958977
impl<'a> InstalledToolchain<'a> for DistributableToolchain<'a> {

0 commit comments

Comments
 (0)