Skip to content

Commit 9f58ba2

Browse files
committed
dist: move dist_root out of DownloadCfg
1 parent c849ca7 commit 9f58ba2

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

src/dist/download.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::utils;
2222
const UPDATE_HASH_LEN: usize = 20;
2323

2424
pub struct DownloadCfg<'a> {
25-
pub dist_root: &'a str,
2625
pub tmp_cx: &'a temp::Context,
2726
pub download_dir: &'a PathBuf,
2827
pub(crate) notify_handler: &'a dyn Fn(Notification<'_>),
@@ -33,7 +32,6 @@ impl<'a> DownloadCfg<'a> {
3332
/// construct a download configuration
3433
pub(crate) fn new(cfg: &'a Cfg<'a>) -> Self {
3534
DownloadCfg {
36-
dist_root: &cfg.dist_root_url,
3735
tmp_cx: &cfg.tmp_cx,
3836
download_dir: &cfg.download_dir,
3937
notify_handler: &*cfg.notify_handler,

src/dist/manifestation.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ impl Manifestation {
463463
use std::path::PathBuf;
464464
let dld_dir = PathBuf::from("bogus");
465465
let dlcfg = DownloadCfg {
466-
dist_root: "bogus",
467466
download_dir: &dld_dir,
468467
tmp_cx,
469468
notify_handler,

src/dist/manifestation/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ impl TestContext {
480480
force: bool,
481481
) -> Result<UpdateStatus> {
482482
let dl_cfg = DownloadCfg {
483-
dist_root: "phony",
484483
tmp_cx: &self.tmp_cx,
485484
download_dir: &self.download_dir,
486485
notify_handler: &|event| println!("{event}"),

src/dist/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ pub(crate) async fn update_from_dist(
979979
opts.components,
980980
opts.targets,
981981
&mut fetched,
982+
&opts.cfg.dist_root_url,
982983
)
983984
.await;
984985

@@ -1075,13 +1076,15 @@ async fn try_update_from_dist_(
10751076
components: &[&str],
10761077
targets: &[&str],
10771078
fetched: &mut String,
1079+
dist_root: &str,
10781080
) -> Result<Option<String>> {
10791081
let toolchain_str = toolchain.to_string();
10801082
let manifestation = Manifestation::open(prefix.clone(), toolchain.target.clone())?;
10811083

10821084
// TODO: Add a notification about which manifest version is going to be used
10831085
info!("syncing channel updates for {toolchain_str}");
10841086
match dl_v2_manifest(
1087+
dist_root,
10851088
download,
10861089
// Even if manifest has not changed, we must continue to install requested components.
10871090
// So if components or targets is not empty, we skip passing `update_hash` so that
@@ -1189,7 +1192,7 @@ async fn try_update_from_dist_(
11891192
}
11901193

11911194
// If the v2 manifest is not found then try v1
1192-
let manifest = match dl_v1_manifest(download, toolchain).await {
1195+
let manifest = match dl_v1_manifest(dist_root, download, toolchain).await {
11931196
Ok(m) => m,
11941197
Err(err) => match err.downcast_ref::<RustupError>() {
11951198
Some(RustupError::ChecksumFailed { .. }) => return Err(err),
@@ -1232,11 +1235,12 @@ async fn try_update_from_dist_(
12321235
}
12331236

12341237
pub(crate) async fn dl_v2_manifest(
1238+
dist_root: &str,
12351239
download: &DownloadCfg<'_>,
12361240
update_hash: Option<&Path>,
12371241
toolchain: &ToolchainDesc,
12381242
) -> Result<Option<(ManifestV2, String)>> {
1239-
let manifest_url = toolchain.manifest_v2_url(download.dist_root, download.process);
1243+
let manifest_url = toolchain.manifest_v2_url(dist_root, download.process);
12401244
match download
12411245
.download_and_check(&manifest_url, update_hash, ".toml")
12421246
.await
@@ -1281,10 +1285,11 @@ pub(crate) async fn dl_v2_manifest(
12811285
}
12821286

12831287
async fn dl_v1_manifest(
1288+
dist_root: &str,
12841289
download: &DownloadCfg<'_>,
12851290
toolchain: &ToolchainDesc,
12861291
) -> Result<Vec<String>> {
1287-
let root_url = toolchain.package_dir(download.dist_root);
1292+
let root_url = toolchain.package_dir(dist_root);
12881293

12891294
if let Channel::Version(ver) = &toolchain.channel {
12901295
// This is an explicit version. In v1 there was no manifest,
@@ -1293,7 +1298,7 @@ async fn dl_v1_manifest(
12931298
return Ok(vec![installer_name]);
12941299
}
12951300

1296-
let manifest_url = toolchain.manifest_v1_url(download.dist_root, download.process);
1301+
let manifest_url = toolchain.manifest_v1_url(dist_root, download.process);
12971302
let manifest_dl = download.download_and_check(&manifest_url, None, "").await?;
12981303
let (manifest_file, _) = manifest_dl.unwrap();
12991304
let manifest_str = utils::read_file("manifest", &manifest_file)?;

src/toolchain/distributable.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,13 @@ impl<'a> DistributableToolchain<'a> {
523523
}
524524

525525
pub async fn show_dist_version(&self) -> anyhow::Result<Option<String>> {
526+
let dist_root = &self.toolchain.cfg.dist_root_url;
526527
let update_hash = self.toolchain.cfg.get_hash_file(&self.desc, false)?;
527528
let download_cfg = DownloadCfg::new(self.toolchain.cfg);
528529

529-
match crate::dist::dl_v2_manifest(&download_cfg, Some(&update_hash), &self.desc).await? {
530+
match crate::dist::dl_v2_manifest(dist_root, &download_cfg, Some(&update_hash), &self.desc)
531+
.await?
532+
{
530533
Some((manifest, _)) => Ok(Some(manifest.get_rust_version()?.to_string())),
531534
None => Ok(None),
532535
}

0 commit comments

Comments
 (0)