Skip to content

Commit 002d0f1

Browse files
rbtcollinsdjc
authored andcommitted
Make DistributableToolChain::install async
1 parent 9694b4b commit 002d0f1

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

src/cli/rustup_mode.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -840,13 +840,15 @@ fn update(cfg: &mut Cfg, opts: UpdateOpts) -> Result<utils::ExitCode> {
840840
allow_downgrade,
841841
))?,
842842
Err(RustupError::ToolchainNotInstalled(_)) => {
843-
crate::toolchain::distributable::DistributableToolchain::install(
844-
cfg,
845-
&desc,
846-
&components,
847-
&targets,
848-
profile,
849-
force,
843+
utils::run_future(
844+
crate::toolchain::distributable::DistributableToolchain::install(
845+
cfg,
846+
&desc,
847+
&components,
848+
&targets,
849+
profile,
850+
force,
851+
),
850852
)?
851853
.0
852854
}
@@ -1295,14 +1297,14 @@ fn override_add(
12951297
Err(e @ RustupError::ToolchainNotInstalled(_)) => match &toolchain_name {
12961298
ToolchainName::Custom(_) => Err(e)?,
12971299
ToolchainName::Official(desc) => {
1298-
let status = DistributableToolchain::install(
1300+
let status = utils::run_future(DistributableToolchain::install(
12991301
cfg,
13001302
desc,
13011303
&[],
13021304
&[],
13031305
cfg.get_profile()?,
13041306
false,
1305-
)?
1307+
))?
13061308
.0;
13071309
writeln!(process().stdout().lock())?;
13081310
common::show_channel_update(

src/cli/self_update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,14 +871,14 @@ fn maybe_install_rust(
871871
let mut toolchain = DistributableToolchain::new(&cfg, desc.clone())?;
872872
utils::run_future(toolchain.update(components, targets, cfg.get_profile()?))?
873873
} else {
874-
DistributableToolchain::install(
874+
utils::run_future(DistributableToolchain::install(
875875
&cfg,
876876
desc,
877877
components,
878878
targets,
879879
cfg.get_profile()?,
880880
true,
881-
)?
881+
))?
882882
.0
883883
};
884884

src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,14 +786,14 @@ impl Cfg {
786786
let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect();
787787
let toolchain = match DistributableToolchain::new(self, toolchain.clone()) {
788788
Err(RustupError::ToolchainNotInstalled(_)) => {
789-
DistributableToolchain::install(
789+
utils::run_future(DistributableToolchain::install(
790790
self,
791791
&toolchain,
792792
&components,
793793
&targets,
794794
profile.unwrap_or(Profile::Default),
795795
false,
796-
)?
796+
))?
797797
.1
798798
}
799799
Ok(mut distributable) => {
@@ -944,14 +944,14 @@ impl Cfg {
944944
match DistributableToolchain::new(self, desc.clone()) {
945945
Err(RustupError::ToolchainNotInstalled(_)) => {
946946
if install_if_missing {
947-
DistributableToolchain::install(
947+
utils::run_future(DistributableToolchain::install(
948948
self,
949949
desc,
950950
&[],
951951
&[],
952952
self.get_profile()?,
953953
true,
954-
)?;
954+
))?;
955955
}
956956
}
957957
o => {

src/toolchain/distributable.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'a> DistributableToolchain<'a> {
327327
}
328328

329329
#[cfg_attr(feature = "otel", tracing::instrument(err, skip_all))]
330-
pub(crate) fn install(
330+
pub(crate) async fn install(
331331
cfg: &'a Cfg,
332332
desc: &'_ ToolchainDesc,
333333
components: &[&str],
@@ -338,22 +338,21 @@ 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 = 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-
)?;
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()
355+
.await?;
357356
Ok((status, Self::new(cfg, desc.clone())?))
358357
}
359358

@@ -367,7 +366,15 @@ impl<'a> DistributableToolchain<'a> {
367366
(cfg.notify_handler)(Notification::UsingExistingToolchain(desc));
368367
Ok(UpdateStatus::Unchanged)
369368
} else {
370-
Ok(Self::install(cfg, desc, &[], &[], cfg.get_profile()?, false)?.0)
369+
Ok(utils::run_future(Self::install(
370+
cfg,
371+
desc,
372+
&[],
373+
&[],
374+
cfg.get_profile()?,
375+
false,
376+
))?
377+
.0)
371378
}
372379
}
373380

0 commit comments

Comments
 (0)