Skip to content

Commit f2e4704

Browse files
rbtcollinsdjc
authored andcommitted
Make dist::dl_*_manifest async
1 parent f10a198 commit f2e4704

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/dist/dist.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ fn try_update_from_dist_(
898898

899899
// TODO: Add a notification about which manifest version is going to be used
900900
(download.notify_handler)(Notification::DownloadingManifest(&toolchain_str));
901-
match dl_v2_manifest(
901+
match utils::run_future(dl_v2_manifest(
902902
download,
903903
// Even if manifest has not changed, we must continue to install requested components.
904904
// So if components or targets is not empty, we skip passing `update_hash` so that
@@ -909,7 +909,7 @@ fn try_update_from_dist_(
909909
None
910910
},
911911
toolchain,
912-
) {
912+
)) {
913913
Ok(Some((m, hash))) => {
914914
(download.notify_handler)(Notification::DownloadedManifest(
915915
&m.date,
@@ -1012,7 +1012,7 @@ fn try_update_from_dist_(
10121012
}
10131013

10141014
// If the v2 manifest is not found then try v1
1015-
let manifest = match dl_v1_manifest(download, toolchain) {
1015+
let manifest = match utils::run_future(dl_v1_manifest(download, toolchain)) {
10161016
Ok(m) => m,
10171017
Err(any) => {
10181018
enum Cases {
@@ -1068,13 +1068,16 @@ fn try_update_from_dist_(
10681068
}
10691069
}
10701070

1071-
pub(crate) fn dl_v2_manifest(
1071+
pub(crate) async fn dl_v2_manifest(
10721072
download: DownloadCfg<'_>,
10731073
update_hash: Option<&Path>,
10741074
toolchain: &ToolchainDesc,
10751075
) -> Result<Option<(ManifestV2, String)>> {
10761076
let manifest_url = toolchain.manifest_v2_url(download.dist_root);
1077-
match utils::run_future(download.download_and_check(&manifest_url, update_hash, ".toml")) {
1077+
match download
1078+
.download_and_check(&manifest_url, update_hash, ".toml")
1079+
.await
1080+
{
10781081
Ok(manifest_dl) => {
10791082
// Downloaded ok!
10801083
let (manifest_file, manifest_hash) = if let Some(m) = manifest_dl {
@@ -1097,7 +1100,10 @@ pub(crate) fn dl_v2_manifest(
10971100
}
10981101
}
10991102

1100-
fn dl_v1_manifest(download: DownloadCfg<'_>, toolchain: &ToolchainDesc) -> Result<Vec<String>> {
1103+
async fn dl_v1_manifest(
1104+
download: DownloadCfg<'_>,
1105+
toolchain: &ToolchainDesc,
1106+
) -> Result<Vec<String>> {
11011107
let root_url = toolchain.package_dir(download.dist_root);
11021108

11031109
if !["nightly", "beta", "stable"].contains(&&*toolchain.channel) {
@@ -1111,7 +1117,7 @@ fn dl_v1_manifest(download: DownloadCfg<'_>, toolchain: &ToolchainDesc) -> Resul
11111117
}
11121118

11131119
let manifest_url = toolchain.manifest_v1_url(download.dist_root);
1114-
let manifest_dl = utils::run_future(download.download_and_check(&manifest_url, None, ""))?;
1120+
let manifest_dl = download.download_and_check(&manifest_url, None, "").await?;
11151121
let (manifest_file, _) = manifest_dl.unwrap();
11161122
let manifest_str = utils::read_file("manifest", &manifest_file)?;
11171123
let urls = manifest_str

src/toolchain/distributable.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,11 @@ impl<'a> DistributableToolchain<'a> {
527527
&|n: crate::dist::Notification<'_>| (self.cfg.notify_handler)(n.into());
528528
let download_cfg = self.cfg.download_cfg(&notify_handler);
529529

530-
match crate::dist::dist::dl_v2_manifest(download_cfg, Some(&update_hash), &self.desc)? {
530+
match utils::run_future(crate::dist::dist::dl_v2_manifest(
531+
download_cfg,
532+
Some(&update_hash),
533+
&self.desc,
534+
))? {
531535
Some((manifest, _)) => Ok(Some(manifest.get_rust_version()?.to_string())),
532536
None => Ok(None),
533537
}

0 commit comments

Comments
 (0)