Skip to content

Commit fa1d7f7

Browse files
rbtcollinsdjc
authored andcommitted
Make InstallMethod::install async
1 parent 8a49393 commit fa1d7f7

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

src/cli/rustup_mode.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,14 +1250,16 @@ fn toolchain_link(cfg: &Cfg, dest: &CustomToolchainName, src: &Path) -> Result<u
12501250
utils::assert_is_file(&pathbuf)?;
12511251

12521252
if true {
1253-
InstallMethod::Link {
1254-
src: &utils::to_absolute(src)?,
1255-
dest,
1256-
cfg,
1257-
}
1258-
.install()?;
1253+
utils::run_future(
1254+
InstallMethod::Link {
1255+
src: &utils::to_absolute(src)?,
1256+
dest,
1257+
cfg,
1258+
}
1259+
.install(),
1260+
)?;
12591261
} else {
1260-
InstallMethod::Copy { src, dest, cfg }.install()?;
1262+
utils::run_future(InstallMethod::Copy { src, dest, cfg }.install())?;
12611263
}
12621264

12631265
Ok(utils::ExitCode(0))

src/install.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) enum InstallMethod<'a> {
5959
impl<'a> InstallMethod<'a> {
6060
// Install a toolchain
6161
#[cfg_attr(feature = "otel", tracing::instrument(err, skip_all))]
62-
pub(crate) fn install(&self) -> Result<UpdateStatus> {
62+
pub(crate) async fn install(&self) -> Result<UpdateStatus> {
6363
let nh = self.cfg().notify_handler.clone();
6464
match self {
6565
InstallMethod::Copy { .. }
@@ -72,9 +72,11 @@ impl<'a> InstallMethod<'a> {
7272
}
7373

7474
(self.cfg().notify_handler)(RootNotification::ToolchainDirectory(&self.dest_path()));
75-
let updated = utils::run_future(self.run(&self.dest_path(), &|n| {
76-
(self.cfg().notify_handler)(n.into())
77-
}))?;
75+
let updated = self
76+
.run(&self.dest_path(), &|n| {
77+
(self.cfg().notify_handler)(n.into())
78+
})
79+
.await?;
7880

7981
let status = match updated {
8082
false => {

src/toolchain/distributable.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,22 @@ impl<'a> DistributableToolchain<'a> {
338338
let hash_path = cfg.get_hash_file(desc, true)?;
339339
let update_hash = Some(&hash_path as &Path);
340340

341-
let status = InstallMethod::Dist {
342-
cfg,
343-
desc,
344-
profile,
345-
update_hash,
346-
dl_cfg: cfg.download_cfg(&|n| (cfg.notify_handler)(n.into())),
347-
force,
348-
allow_downgrade: false,
349-
exists: false,
350-
old_date_version: None,
351-
components,
352-
targets,
353-
}
354-
.install()?;
341+
let status = utils::run_future(
342+
InstallMethod::Dist {
343+
cfg,
344+
desc,
345+
profile,
346+
update_hash,
347+
dl_cfg: cfg.download_cfg(&|n| (cfg.notify_handler)(n.into())),
348+
force,
349+
allow_downgrade: false,
350+
exists: false,
351+
old_date_version: None,
352+
components,
353+
targets,
354+
}
355+
.install(),
356+
)?;
355357
Ok((status, Self::new(cfg, desc.clone())?))
356358
}
357359

@@ -407,22 +409,24 @@ impl<'a> DistributableToolchain<'a> {
407409
let hash_path = self.cfg.get_hash_file(&self.desc, true)?;
408410
let update_hash = Some(&hash_path as &Path);
409411

410-
InstallMethod::Dist {
411-
cfg: self.cfg,
412-
desc: &self.desc,
413-
profile,
414-
update_hash,
415-
dl_cfg: self
416-
.cfg
417-
.download_cfg(&|n| (self.cfg.notify_handler)(n.into())),
418-
force,
419-
allow_downgrade,
420-
exists: true,
421-
old_date_version,
422-
components,
423-
targets,
424-
}
425-
.install()
412+
utils::run_future(
413+
InstallMethod::Dist {
414+
cfg: self.cfg,
415+
desc: &self.desc,
416+
profile,
417+
update_hash,
418+
dl_cfg: self
419+
.cfg
420+
.download_cfg(&|n| (self.cfg.notify_handler)(n.into())),
421+
force,
422+
allow_downgrade,
423+
exists: true,
424+
old_date_version,
425+
components,
426+
targets,
427+
}
428+
.install(),
429+
)
426430
}
427431

428432
pub fn recursion_error(&self, binary_lossy: String) -> Result<Infallible, anyhow::Error> {

0 commit comments

Comments
 (0)