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 { diff --git a/src/dist/mod.rs b/src/dist/mod.rs index 239d5227a4..031853a421 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -10,9 +10,13 @@ use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; use thiserror::Error as ThisError; +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, }; @@ -1152,9 +1156,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)?; @@ -1167,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 - (download.notify_handler)(Notification::ManifestChecksumFailedHack); + 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/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}'") 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)), 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; }