Skip to content

Commit 7dbf604

Browse files
committed
dist: avoid recomputing dist root URL
1 parent bd74375 commit 7dbf604

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ impl<'a> Cfg<'a> {
944944

945945
/// The root path of the release server, without the `/dist` suffix.
946946
/// By default, it points to [`dist::DEFAULT_DIST_SERVER`].
947-
pub(crate) fn dist_root_server(process: &Process) -> Result<String> {
947+
fn dist_root_server(process: &Process) -> Result<String> {
948948
if let Some(s) = process.var_opt("RUSTUP_DIST_SERVER")? {
949949
trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
950950
return Ok(s);

src/dist/mod.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ use serde::{Deserialize, Serialize};
1313
use thiserror::Error as ThisError;
1414
use tracing::{debug, info, warn};
1515

16-
use crate::{
17-
config::{Cfg, dist_root_server},
18-
errors::RustupError,
19-
process::Process,
20-
toolchain::ToolchainName,
21-
utils,
22-
};
16+
use crate::{config::Cfg, errors::RustupError, process::Process, toolchain::ToolchainName, utils};
2317

2418
pub mod component;
2519
pub(crate) mod config;
@@ -977,7 +971,7 @@ pub(crate) async fn update_from_dist(
977971
opts.components,
978972
opts.targets,
979973
&mut fetched,
980-
&opts.cfg.dist_root_url,
974+
opts.cfg,
981975
)
982976
.await;
983977

@@ -1074,15 +1068,14 @@ async fn try_update_from_dist_(
10741068
components: &[&str],
10751069
targets: &[&str],
10761070
fetched: &mut String,
1077-
dist_root: &str,
1071+
cfg: &Cfg<'_>,
10781072
) -> Result<Option<String>> {
10791073
let toolchain_str = toolchain.to_string();
10801074
let manifestation = Manifestation::open(prefix.clone(), toolchain.target.clone())?;
10811075

10821076
// TODO: Add a notification about which manifest version is going to be used
10831077
info!("syncing channel updates for {toolchain_str}");
10841078
match dl_v2_manifest(
1085-
dist_root,
10861079
download,
10871080
// Even if manifest has not changed, we must continue to install requested components.
10881081
// So if components or targets is not empty, we skip passing `update_hash` so that
@@ -1093,6 +1086,7 @@ async fn try_update_from_dist_(
10931086
None
10941087
},
10951088
toolchain,
1089+
cfg,
10961090
)
10971091
.await
10981092
{
@@ -1190,7 +1184,7 @@ async fn try_update_from_dist_(
11901184
}
11911185

11921186
// If the v2 manifest is not found then try v1
1193-
let manifest = match dl_v1_manifest(dist_root, download, toolchain).await {
1187+
let manifest = match dl_v1_manifest(&cfg.dist_root_url, download, toolchain).await {
11941188
Ok(m) => m,
11951189
Err(err) => match err.downcast_ref::<RustupError>() {
11961190
Some(RustupError::ChecksumFailed { .. }) => return Err(err),
@@ -1227,12 +1221,12 @@ async fn try_update_from_dist_(
12271221
}
12281222

12291223
pub(crate) async fn dl_v2_manifest(
1230-
dist_root: &str,
12311224
download: &DownloadCfg<'_>,
12321225
update_hash: Option<&Path>,
12331226
toolchain: &ToolchainDesc,
1227+
cfg: &Cfg<'_>,
12341228
) -> Result<Option<(ManifestV2, String)>> {
1235-
let manifest_url = toolchain.manifest_v2_url(dist_root, download.process);
1229+
let manifest_url = toolchain.manifest_v2_url(&cfg.dist_root_url, download.process);
12361230
match download
12371231
.download_and_check(&manifest_url, update_hash, None, ".toml")
12381232
.await
@@ -1258,15 +1252,15 @@ pub(crate) async fn dl_v2_manifest(
12581252
// Manifest checksum mismatched.
12591253
warn!("{err}");
12601254

1261-
let server = dist_root_server(download.process)?;
1262-
if server == DEFAULT_DIST_SERVER {
1255+
if cfg.dist_root_url.starts_with(DEFAULT_DIST_SERVER) {
12631256
info!(
12641257
"this is likely due to an ongoing update of the official release server, please try again later"
12651258
);
12661259
info!("see <https://github.com/rust-lang/rustup/issues/3390> for more details");
12671260
} else {
12681261
info!(
1269-
"this might indicate an issue with the third-party release server '{server}'"
1262+
"this might indicate an issue with the third-party release server '{}'",
1263+
cfg.dist_root_url
12701264
);
12711265
info!("see <https://github.com/rust-lang/rustup/issues/3885> for more details");
12721266
}

src/toolchain/distributable.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,13 @@ impl<'a> DistributableToolchain<'a> {
519519
}
520520

521521
pub async fn show_dist_version(&self) -> anyhow::Result<Option<String>> {
522-
let dist_root = &self.toolchain.cfg.dist_root_url;
523-
let update_hash = self.toolchain.cfg.get_hash_file(&self.desc, false)?;
524-
let download_cfg = DownloadCfg::new(self.toolchain.cfg);
525-
526-
match crate::dist::dl_v2_manifest(dist_root, &download_cfg, Some(&update_hash), &self.desc)
527-
.await?
522+
match crate::dist::dl_v2_manifest(
523+
&DownloadCfg::new(self.toolchain.cfg),
524+
Some(&self.toolchain.cfg.get_hash_file(&self.desc, false)?),
525+
&self.desc,
526+
self.toolchain.cfg,
527+
)
528+
.await?
528529
{
529530
Some((manifest, _)) => Ok(Some(manifest.get_rust_version()?.to_string())),
530531
None => Ok(None),

0 commit comments

Comments
 (0)