From 40288bd4f851b719e3f9c7c12bbe88a09e29f908 Mon Sep 17 00:00:00 2001 From: rami3l Date: Sun, 7 Jul 2024 11:56:55 +0800 Subject: [PATCH 1/5] refactor(install): avoid extra clone in `InstallMethod::install` --- src/install.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/install.rs b/src/install.rs index f968b4da37..cb0cf2ee24 100644 --- a/src/install.rs +++ b/src/install.rs @@ -39,31 +39,27 @@ impl<'a> InstallMethod<'a> { // Install a toolchain #[cfg_attr(feature = "otel", tracing::instrument(err, skip_all))] pub(crate) async fn install(&self) -> Result { - let nh = self.cfg().notify_handler.clone(); + let nh = &self.cfg().notify_handler; match self { InstallMethod::Copy { .. } | InstallMethod::Link { .. } | InstallMethod::Dist(DistOptions { old_date_version: None, .. - }) => (nh)(RootNotification::InstallingToolchain(&self.dest_basename())), - _ => (nh)(RootNotification::UpdatingToolchain(&self.dest_basename())), + }) => nh(RootNotification::InstallingToolchain(&self.dest_basename())), + _ => nh(RootNotification::UpdatingToolchain(&self.dest_basename())), } - (self.cfg().notify_handler)(RootNotification::ToolchainDirectory(&self.dest_path())); - let updated = self - .run(&self.dest_path(), &|n| { - (self.cfg().notify_handler)(n.into()) - }) - .await?; + nh(RootNotification::ToolchainDirectory(&self.dest_path())); + let updated = self.run(&self.dest_path(), &|n| nh(n.into())).await?; let status = match updated { false => { - (nh)(RootNotification::UpdateHashMatches); + nh(RootNotification::UpdateHashMatches); UpdateStatus::Unchanged } true => { - (nh)(RootNotification::InstalledToolchain(&self.dest_basename())); + nh(RootNotification::InstalledToolchain(&self.dest_basename())); match self { InstallMethod::Dist(DistOptions { old_date_version: Some((_, v)), From ed5c84c1a222c8b7f0a3c5537510c4f00d16db22 Mon Sep 17 00:00:00 2001 From: rami3l Date: Sun, 7 Jul 2024 12:47:42 +0800 Subject: [PATCH 2/5] refactor(dist/notifications)!: inline usages of `Notification::ManifestChecksumFailedHack` --- src/dist/mod.rs | 3 ++- src/dist/notifications.rs | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/dist/mod.rs b/src/dist/mod.rs index 239d5227a4..f64b036a45 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -10,6 +10,7 @@ use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; use thiserror::Error as ThisError; +use tracing::info; use crate::{ config::Cfg, currentprocess::Process, errors::RustupError, toolchain::ToolchainName, @@ -1169,7 +1170,7 @@ pub(crate) async fn dl_v2_manifest( Err(any) => { if let Some(RustupError::ChecksumFailed { .. }) = any.downcast_ref::() { // Checksum failed - issue warning to try again later - (download.notify_handler)(Notification::ManifestChecksumFailedHack); + info!("update not yet available, sorry! try again later") } Err(any) } diff --git a/src/dist/notifications.rs b/src/dist/notifications.rs index 38ada94fb9..fa901bc1eb 100644 --- a/src/dist/notifications.rs +++ b/src/dist/notifications.rs @@ -32,7 +32,6 @@ pub enum Notification<'a> { DownloadingLegacyManifest, SkippingNightlyMissingComponent(&'a ToolchainDesc, &'a Manifest, &'a [Component]), ForcingUnavailableComponent(&'a str), - ManifestChecksumFailedHack, ComponentUnavailable(&'a str, Option<&'a TargetTriple>), StrayHash(&'a Path), SignatureInvalid(&'a str), @@ -67,7 +66,6 @@ impl<'a> Notification<'a> { | RemovingComponent(_, _, _) | RemovingOldComponent(_, _, _) | ComponentAlreadyInstalled(_) - | ManifestChecksumFailedHack | RollingBack | DownloadingManifest(_) | SkippingNightlyMissingComponent(_, _, _) @@ -150,9 +148,6 @@ impl<'a> Display for Notification<'a> { write!(f, "latest update on {date}, no rust version") } DownloadingLegacyManifest => write!(f, "manifest not found. trying legacy manifest"), - ManifestChecksumFailedHack => { - write!(f, "update not yet available, sorry! try again later") - } ComponentUnavailable(pkg, toolchain) => { if let Some(tc) = toolchain { write!(f, "component '{pkg}' is not available on target '{tc}'") From 08d988ba5f49340ad4feffe0db4c76cdbf0423fe Mon Sep 17 00:00:00 2001 From: rami3l Date: Sun, 7 Jul 2024 19:02:01 +0800 Subject: [PATCH 3/5] refactor(dist): use `let-else` in `dl_v2_manifest()` --- src/dist/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dist/mod.rs b/src/dist/mod.rs index f64b036a45..a8180900b9 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -1153,9 +1153,7 @@ pub(crate) async fn dl_v2_manifest( { Ok(manifest_dl) => { // Downloaded ok! - let (manifest_file, manifest_hash) = if let Some(m) = manifest_dl { - m - } else { + let Some((manifest_file, manifest_hash)) = manifest_dl else { return Ok(None); }; let manifest_str = utils::read_file("manifest", &manifest_file)?; From 1445a68c59ba6d828086227fd064c168e489432b Mon Sep 17 00:00:00 2001 From: rami3l Date: Mon, 8 Jul 2024 19:27:22 +0800 Subject: [PATCH 4/5] refactor(config): extract `dist_root_server()` --- src/config.rs | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/config.rs b/src/config.rs index c64b9c3695..ec56c15a97 100644 --- a/src/config.rs +++ b/src/config.rs @@ -293,21 +293,7 @@ impl<'a> Cfg<'a> { .map(|t| t.resolve(&default_host_triple)) .transpose()?; - let dist_root_server = match non_empty_env_var("RUSTUP_DIST_SERVER", process)? { - Some(s) => { - trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`"); - s - } - None => { - // For backward compatibility - non_empty_env_var("RUSTUP_DIST_ROOT", process)? - .inspect(|url| trace!("`RUSTUP_DIST_ROOT` has been set to `{url}`")) - .as_ref() - .map(|root| root.trim_end_matches("/dist")) - .unwrap_or(dist::DEFAULT_DIST_SERVER) - .to_owned() - } - }; + let dist_root_server = dist_root_server(process)?; let notify_clone = notify_handler.clone(); let tmp_cx = temp::Context::new( @@ -950,6 +936,24 @@ impl<'a> Cfg<'a> { } } +pub(crate) fn dist_root_server(process: &Process) -> Result { + Ok(match non_empty_env_var("RUSTUP_DIST_SERVER", process)? { + Some(s) => { + trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`"); + s + } + None => { + // For backward compatibility + non_empty_env_var("RUSTUP_DIST_ROOT", process)? + .inspect(|url| trace!("`RUSTUP_DIST_ROOT` has been set to `{url}`")) + .as_ref() + .map(|root| root.trim_end_matches("/dist")) + .unwrap_or(dist::DEFAULT_DIST_SERVER) + .to_owned() + } + }) +} + impl<'a> Debug for Cfg<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { From c60bc6478fab022bafaef6aaa50fa20dc7776ac9 Mon Sep 17 00:00:00 2001 From: rami3l Date: Sun, 7 Jul 2024 12:31:54 +0800 Subject: [PATCH 5/5] feat(dist): refine suggestions regarding manifest checksum mismatches --- src/dist/mod.rs | 24 +++++++++++++++++++----- tests/suite/cli_v2.rs | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/dist/mod.rs b/src/dist/mod.rs index a8180900b9..031853a421 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -10,10 +10,13 @@ use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; use thiserror::Error as ThisError; -use tracing::info; +use tracing::{info, warn}; use crate::{ - config::Cfg, currentprocess::Process, errors::RustupError, toolchain::ToolchainName, + config::{dist_root_server, Cfg}, + currentprocess::Process, + errors::RustupError, + toolchain::ToolchainName, utils::utils, }; @@ -1166,9 +1169,20 @@ pub(crate) async fn dl_v2_manifest( Ok(Some((manifest, manifest_hash))) } Err(any) => { - if let Some(RustupError::ChecksumFailed { .. }) = any.downcast_ref::() { - // Checksum failed - issue warning to try again later - info!("update not yet available, sorry! try again later") + if let Some(err @ RustupError::ChecksumFailed { .. }) = + any.downcast_ref::() + { + // Manifest checksum mismatched. + warn!("{err}"); + + let server = dist_root_server(download.process)?; + if server == DEFAULT_DIST_SERVER { + info!("this is likely due to an ongoing update of the official release server, please try again later"); + info!("see for more details"); + } else { + info!("this might indicate an issue with the third-party release server '{server}'"); + info!("see for more details"); + } } Err(any) } diff --git a/tests/suite/cli_v2.rs b/tests/suite/cli_v2.rs index a4bd1fa330..63c50b3348 100644 --- a/tests/suite/cli_v2.rs +++ b/tests/suite/cli_v2.rs @@ -381,7 +381,7 @@ async fn bad_sha_on_manifest() { cx.config .expect_err( &["rustup", "default", "nightly"], - "update not yet available", + "info: this might indicate an issue with the third-party release server", ) .await; }