Skip to content

Commit eb90b85

Browse files
committed
dist: install updates directly via DistOptions
1 parent 4eaf83d commit eb90b85

File tree

6 files changed

+54
-68
lines changed

6 files changed

+54
-68
lines changed

src/cli/common.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
1616

1717
use crate::{
1818
config::Cfg,
19-
dist::{TargetTriple, ToolchainDesc},
19+
dist::{DistOptions, TargetTriple, ToolchainDesc},
2020
errors::RustupError,
21-
install::UpdateStatus,
21+
install::{InstallMethod, UpdateStatus},
2222
process::Process,
2323
toolchain::{LocalToolchainName, Toolchain, ToolchainName},
2424
utils,
@@ -217,10 +217,10 @@ pub(crate) async fn update_all_channels(
217217
) -> Result<utils::ExitCode> {
218218
let profile = cfg.get_profile()?;
219219
let mut toolchains = Vec::new();
220-
for (desc, mut distributable) in cfg.list_channels()? {
221-
let result = distributable
222-
.update(&[], &[], profile, force_update, false)
223-
.await;
220+
for (desc, distributable) in cfg.list_channels()? {
221+
let options = DistOptions::new(&[], &[], &desc, Some(profile), force_update, cfg)?
222+
.for_update(&distributable, false);
223+
let result = InstallMethod::Dist(options).install().await;
224224

225225
if let Err(e) = &result {
226226
error!("{e}");

src/cli/rustup_mode.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -960,18 +960,15 @@ async fn update(
960960

961961
let components = opts.component.iter().map(|s| &**s).collect::<Vec<_>>();
962962
let targets = opts.target.iter().map(|s| &**s).collect::<Vec<_>>();
963+
let dist_opts = DistOptions::new(&components, &targets, &desc, None, opts.force, cfg)?;
963964

964-
let force = opts.force;
965-
let allow_downgrade = opts.allow_downgrade;
966965
let status = match DistributableToolchain::new(cfg, desc.clone()) {
967-
Ok(mut d) => {
968-
let profile = cfg.get_profile()?;
969-
d.update(&components, &targets, profile, force, allow_downgrade)
966+
Ok(d) => {
967+
InstallMethod::Dist(dist_opts.for_update(&d, opts.allow_downgrade))
968+
.install()
970969
.await?
971970
}
972971
Err(RustupError::ToolchainNotInstalled { .. }) => {
973-
let dist_opts =
974-
DistOptions::new(&components, &targets, &desc, None, force, cfg)?;
975972
DistributableToolchain::install(dist_opts).await?.0
976973
}
977974
Err(e) => Err(e)?,

src/cli/self_update.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use serde::{Deserialize, Serialize};
5252
use tracing::{error, info, trace, warn};
5353

5454
use crate::dist::DistOptions;
55+
use crate::install::InstallMethod;
5556
use crate::{
5657
DUP_TOOLS, TOOLS,
5758
cli::{
@@ -997,16 +998,17 @@ async fn maybe_install_rust(opts: InstallOpts<'_>, cfg: &mut Cfg<'_>) -> Result<
997998
let (components, targets) = (opts.components, opts.targets);
998999
let toolchain = opts.install(cfg)?;
9991000
if let Some(desc) = &toolchain {
1001+
let options = DistOptions::new(components, targets, desc, None, true, cfg)?;
10001002
let status = if Toolchain::exists(cfg, &desc.into())? {
10011003
warn!("Updating existing toolchain, profile choice will be ignored");
10021004
// If we have a partial install we might not be able to read content here. We could:
10031005
// - fail and folk have to delete the partially present toolchain to recover
10041006
// - silently ignore it (and provide inconsistent metadata for reporting the install/update change)
10051007
// - delete the partial install and start over
10061008
// For now, we error.
1007-
let mut toolchain = DistributableToolchain::new(cfg, desc.clone())?;
1008-
toolchain
1009-
.update(components, targets, cfg.get_profile()?, true, false)
1009+
let toolchain = DistributableToolchain::new(cfg, desc.clone())?;
1010+
InstallMethod::Dist(options.for_update(&toolchain, true))
1011+
.install()
10101012
.await?
10111013
} else {
10121014
let options = DistOptions::new(components, targets, desc, None, true, cfg)?;

src/config.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use thiserror::Error as ThisError;
99
use tracing::{debug, error, info, trace, warn};
1010

1111
use crate::dist::{AutoInstallMode, DistOptions};
12+
use crate::install::InstallMethod;
1213
use crate::{
1314
cli::{common, self_update::SelfUpdateMode},
1415
dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc, temp},
@@ -787,25 +788,19 @@ impl<'a> Cfg<'a> {
787788
}
788789
let components: Vec<_> = components.iter().map(AsRef::as_ref).collect();
789790
let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect();
791+
let options = DistOptions::new(&components, &targets, toolchain, profile, false, self)?;
790792

791793
let (status, toolchain) = match DistributableToolchain::new(self, toolchain.clone()) {
792794
Err(RustupError::ToolchainNotInstalled { .. }) => {
793-
let options =
794-
DistOptions::new(&components, &targets, toolchain, profile, false, self)?;
795795
DistributableToolchain::install(options).await?
796796
}
797-
Ok(mut distributable) => {
797+
Ok(distributable) => {
798798
if verbose {
799799
info!("using existing install for {toolchain}");
800800
}
801801
let status = if !distributable.components_exist(&components, &targets)? {
802-
let profile = match profile {
803-
Some(profile) => profile,
804-
None => self.get_profile()?,
805-
};
806-
807-
distributable
808-
.update(&components, &targets, profile, true, false)
802+
InstallMethod::Dist(options.for_update(&distributable, false))
803+
.install()
809804
.await?
810805
} else {
811806
UpdateStatus::Unchanged

src/dist/mod.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ use serde::{Deserialize, Serialize};
1919
use thiserror::Error as ThisError;
2020
use tracing::{debug, info, warn};
2121

22-
use crate::{config::Cfg, errors::RustupError, process::Process, toolchain::ToolchainName, utils};
22+
use crate::{
23+
config::Cfg,
24+
errors::RustupError,
25+
process::Process,
26+
toolchain::{DistributableToolchain, ToolchainName},
27+
utils,
28+
};
2329

2430
pub mod component;
2531
pub(crate) mod config;
@@ -922,6 +928,31 @@ impl<'cfg, 'a> DistOptions<'cfg, 'a> {
922928
targets,
923929
})
924930
}
931+
932+
pub(super) fn for_update(
933+
mut self,
934+
toolchain: &'a DistributableToolchain<'cfg>,
935+
allow_downgrade: bool,
936+
) -> Self {
937+
self.allow_downgrade = allow_downgrade;
938+
self.exists = true;
939+
self.old_date_version =
940+
// Ignore a missing manifest: we can't report the old version
941+
// correctly, and it probably indicates an incomplete install, so do
942+
// not report an old rustc version either.
943+
toolchain.get_manifest()
944+
.map(|m| {
945+
(
946+
m.date,
947+
// should rustc_version be a free function on a trait?
948+
// note that prev_version can be junk if the rustc component is missing ...
949+
toolchain.toolchain.rustc_version(),
950+
)
951+
})
952+
.ok();
953+
954+
self
955+
}
925956
}
926957

927958
// Installs or updates a toolchain from a dist server. If an initial

src/toolchain/distributable.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
RustupError, component_for_bin,
1212
config::{ActiveSource, Cfg},
1313
dist::{
14-
DistOptions, PartialToolchainDesc, Profile, ToolchainDesc,
14+
DistOptions, PartialToolchainDesc, ToolchainDesc,
1515
config::Config,
1616
download::DownloadCfg,
1717
manifest::{Component, ComponentStatus, Manifest},
@@ -29,7 +29,7 @@ use super::{
2929
/// An official toolchain installed on the local disk
3030
#[derive(Debug)]
3131
pub(crate) struct DistributableToolchain<'a> {
32-
pub(super) toolchain: Toolchain<'a>,
32+
pub(crate) toolchain: Toolchain<'a>,
3333
desc: ToolchainDesc,
3434
}
3535

@@ -345,45 +345,6 @@ impl<'a> DistributableToolchain<'a> {
345345
InstallPrefix::from(self.toolchain.path().to_owned()).guess_v1_manifest()
346346
}
347347

348-
/// Update a toolchain with control over the channel behaviour
349-
#[tracing::instrument(level = "trace", err(level = "trace"), skip_all)]
350-
pub(crate) async fn update(
351-
&mut self,
352-
components: &[&str],
353-
targets: &[&str],
354-
profile: Profile,
355-
force: bool,
356-
allow_downgrade: bool,
357-
) -> anyhow::Result<UpdateStatus> {
358-
let mut options = DistOptions::new(
359-
components,
360-
targets,
361-
&self.desc,
362-
Some(profile),
363-
force,
364-
self.toolchain.cfg,
365-
)?;
366-
367-
options.allow_downgrade = allow_downgrade;
368-
options.exists = true;
369-
options.old_date_version =
370-
// Ignore a missing manifest: we can't report the old version
371-
// correctly, and it probably indicates an incomplete install, so do
372-
// not report an old rustc version either.
373-
self.get_manifest()
374-
.map(|m| {
375-
(
376-
m.date,
377-
// should rustc_version be a free function on a trait?
378-
// note that prev_version can be junk if the rustc component is missing ...
379-
self.toolchain.rustc_version(),
380-
)
381-
})
382-
.ok();
383-
384-
InstallMethod::Dist(options).install().await
385-
}
386-
387348
pub fn recursion_error(&self, binary_lossy: String) -> Result<Infallible, anyhow::Error> {
388349
let prefix = InstallPrefix::from(self.toolchain.path());
389350
let manifestation = Manifestation::open(prefix, self.desc.target.clone())?;

0 commit comments

Comments
 (0)