Skip to content

feat(dist): refine suggestions regarding manifest checksum mismatches #3923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -950,6 +936,24 @@ impl<'a> Cfg<'a> {
}
}

pub(crate) fn dist_root_server(process: &Process) -> Result<String> {
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 {
Expand Down
27 changes: 20 additions & 7 deletions src/dist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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)?;
Expand All @@ -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::<RustupError>() {
// Checksum failed - issue warning to try again later
(download.notify_handler)(Notification::ManifestChecksumFailedHack);
if let Some(err @ RustupError::ChecksumFailed { .. }) =
any.downcast_ref::<RustupError>()
{
// 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 <https://github.com/rust-lang/rustup/issues/3390> for more details");
} else {
info!("this might indicate an issue with the third-party release server '{server}'");
info!("see <https://github.com/rust-lang/rustup/issues/3885> for more details");
}
}
Err(any)
}
Expand Down
5 changes: 0 additions & 5 deletions src/dist/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -67,7 +66,6 @@ impl<'a> Notification<'a> {
| RemovingComponent(_, _, _)
| RemovingOldComponent(_, _, _)
| ComponentAlreadyInstalled(_)
| ManifestChecksumFailedHack
| RollingBack
| DownloadingManifest(_)
| SkippingNightlyMissingComponent(_, _, _)
Expand Down Expand Up @@ -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}'")
Expand Down
18 changes: 7 additions & 11 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpdateStatus> {
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)),
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/cli_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading