Skip to content

Commit 1fe7153

Browse files
rbtcollinsdjc
authored andcommitted
Make manifestation::update async
1 parent a134371 commit 1fe7153

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/dist/dist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,14 +962,14 @@ fn try_update_from_dist_(
962962

963963
fetched.clone_from(&m.date);
964964

965-
return match manifestation.update(
965+
return match utils::run_future(manifestation.update(
966966
&m,
967967
changes,
968968
force_update,
969969
&download,
970970
&toolchain.manifest_name(),
971971
true,
972-
) {
972+
)) {
973973
Ok(status) => match status {
974974
UpdateStatus::Unchanged => Ok(None),
975975
UpdateStatus::Changed => Ok(Some(hash)),

src/dist/manifestation.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ impl Manifestation {
9898
/// distribution manifest to "rustlib/rustup-dist.toml" and a
9999
/// configuration containing the component name-target pairs to
100100
/// "rustlib/rustup-config.toml".
101-
pub fn update(
101+
///
102+
/// It is *not* safe to run two updates concurrently. See
103+
/// https://github.com/rust-lang/rustup/issues/988 for the details.
104+
pub async fn update(
102105
&self,
103106
new_manifest: &Manifest,
104107
changes: Changes,
@@ -172,7 +175,7 @@ impl Manifestation {
172175

173176
let url_url = utils::parse_url(&url)?;
174177

175-
let downloaded_file = utils::run_future(RetryIf::spawn(
178+
let downloaded_file = RetryIf::spawn(
176179
FixedInterval::from_millis(0).take(max_retries),
177180
|| download_cfg.download(&url_url, &hash),
178181
|e: &anyhow::Error| {
@@ -186,7 +189,8 @@ impl Manifestation {
186189
_ => false,
187190
}
188191
},
189-
))
192+
)
193+
.await
190194
.with_context(|| RustupError::ComponentDownloadFailed(component.name(new_manifest)))?;
191195

192196
things_downloaded.push(hash);

src/dist/manifestation/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,14 @@ fn update_from_dist(
466466
remove_components: remove.to_owned(),
467467
};
468468

469-
manifestation.update(
469+
utils::run_future(manifestation.update(
470470
&manifest,
471471
changes,
472472
force,
473473
download_cfg,
474474
&toolchain.manifest_name(),
475475
true,
476-
)
476+
))
477477
}
478478

479479
fn make_manifest_url(dist_server: &Url, toolchain: &ToolchainDesc) -> Result<Url> {

src/toolchain/distributable.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{
1616
},
1717
install::{InstallMethod, UpdateStatus},
1818
notifications::Notification,
19+
utils::utils,
1920
RustupError,
2021
};
2122

@@ -110,14 +111,14 @@ impl<'a> DistributableToolchain<'a> {
110111
&|n: crate::dist::Notification<'_>| (self.cfg.notify_handler)(n.into());
111112
let download_cfg = self.cfg.download_cfg(&notify_handler);
112113

113-
manifestation.update(
114+
utils::run_future(manifestation.update(
114115
&manifest,
115116
changes,
116117
false,
117118
&download_cfg,
118119
&self.desc.manifest_name(),
119120
false,
120-
)?;
121+
))?;
121122

122123
Ok(())
123124
}
@@ -508,14 +509,14 @@ impl<'a> DistributableToolchain<'a> {
508509
&|n: crate::dist::Notification<'_>| (self.cfg.notify_handler)(n.into());
509510
let download_cfg = self.cfg.download_cfg(&notify_handler);
510511

511-
manifestation.update(
512+
utils::run_future(manifestation.update(
512513
&manifest,
513514
changes,
514515
false,
515516
&download_cfg,
516517
&self.desc.manifest_name(),
517518
false,
518-
)?;
519+
))?;
519520

520521
Ok(())
521522
}

0 commit comments

Comments
 (0)