Skip to content

Commit dc44f64

Browse files
committed
Make InstallMethod::Dist safer to work with
There are enough fields that using a struct type is going to avoid some eventual typo, and readability is aided.
1 parent 18eabcc commit dc44f64

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

src/install.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ pub enum InstallMethod<'a> {
1919
Link(&'a Path, &'a CustomToolchain<'a>),
2020
Installer(&'a Path, &'a temp::Cfg, &'a CustomToolchain<'a>),
2121
// bool is whether to force an update
22-
Dist(
23-
&'a dist::ToolchainDesc,
24-
dist::Profile,
25-
Option<&'a Path>,
26-
DownloadCfg<'a>,
22+
Dist {
23+
desc: &'a dist::ToolchainDesc,
24+
profile: dist::Profile,
25+
update_hash: Option<&'a Path>,
26+
dl_cfg: DownloadCfg<'a>,
2727
// --force
28-
bool,
28+
force_update: bool,
2929
// --allow-downgrade
30-
bool,
30+
allow_downgrade: bool,
3131
// toolchain already exists
32-
bool,
32+
exists: bool,
3333
// currently installed date
34-
Option<&'a str>,
34+
old_date: Option<&'a str>,
3535
// Extra components to install from dist
36-
&'a [&'a str],
36+
components: &'a [&'a str],
3737
// Extra targets to install from dist
38-
&'a [&'a str],
39-
&'a DistributableToolchain<'a>,
40-
),
38+
targets: &'a [&'a str],
39+
distributable: &'a DistributableToolchain<'a>,
40+
},
4141
}
4242

4343
impl<'a> InstallMethod<'a> {
@@ -86,7 +86,7 @@ impl<'a> InstallMethod<'a> {
8686
if path.exists() {
8787
// Don't uninstall first for Dist method
8888
match self {
89-
InstallMethod::Dist(..) | InstallMethod::Installer(..) => {}
89+
InstallMethod::Dist { .. } | InstallMethod::Installer(..) => {}
9090
_ => {
9191
uninstall(path, notify_handler)?;
9292
}
@@ -106,8 +106,8 @@ impl<'a> InstallMethod<'a> {
106106
InstallMethod::tar_gz(src, path, &temp_cfg, notify_handler)?;
107107
Ok(true)
108108
}
109-
InstallMethod::Dist(
110-
toolchain,
109+
InstallMethod::Dist {
110+
desc,
111111
profile,
112112
update_hash,
113113
dl_cfg,
@@ -117,13 +117,13 @@ impl<'a> InstallMethod<'a> {
117117
old_date,
118118
components,
119119
targets,
120-
..,
121-
) => {
120+
..
121+
} => {
122122
let prefix = &InstallPrefix::from(path.to_owned());
123123
let maybe_new_hash = dist::update_from_dist(
124124
dl_cfg,
125125
update_hash,
126-
toolchain,
126+
desc,
127127
if exists { None } else { Some(profile) },
128128
prefix,
129129
force_update,

src/toolchain.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -713,19 +713,19 @@ impl<'a> DistributableToolchain<'a> {
713713
) -> Result<UpdateStatus> {
714714
let update_hash = self.update_hash()?;
715715
let old_date = self.get_manifest().ok().and_then(|m| m.map(|m| m.date));
716-
InstallMethod::Dist(
717-
&self.desc()?,
718-
self.0.cfg.get_profile()?,
719-
Some(&update_hash),
720-
self.0.download_cfg(),
716+
InstallMethod::Dist {
717+
desc: &self.desc()?,
718+
profile: self.0.cfg.get_profile()?,
719+
update_hash: Some(&update_hash),
720+
dl_cfg: self.0.download_cfg(),
721721
force_update,
722722
allow_downgrade,
723-
self.0.exists(),
724-
old_date.as_ref().map(|s| &**s),
723+
exists: self.0.exists(),
724+
old_date: old_date.as_ref().map(|s| &**s),
725725
components,
726726
targets,
727-
&self,
728-
)
727+
distributable: &self,
728+
}
729729
.install(&self.0)
730730
}
731731

@@ -734,19 +734,19 @@ impl<'a> DistributableToolchain<'a> {
734734
let update_hash = self.update_hash()?;
735735
(self.0.cfg.notify_handler)(Notification::LookingForToolchain(&self.0.name));
736736
if !self.0.exists() {
737-
Ok(InstallMethod::Dist(
738-
&self.desc()?,
739-
self.0.cfg.get_profile()?,
740-
Some(&update_hash),
741-
self.0.download_cfg(),
742-
false,
743-
false,
744-
false,
745-
None,
746-
&[],
747-
&[],
748-
&self,
749-
)
737+
Ok(InstallMethod::Dist {
738+
desc: &self.desc()?,
739+
profile: self.0.cfg.get_profile()?,
740+
update_hash: Some(&update_hash),
741+
dl_cfg: self.0.download_cfg(),
742+
force_update: false,
743+
allow_downgrade: false,
744+
exists: false,
745+
old_date: None,
746+
components: &[],
747+
targets: &[],
748+
distributable: &self,
749+
}
750750
.install(&self.0)?)
751751
} else {
752752
(self.0.cfg.notify_handler)(Notification::UsingExistingToolchain(&self.0.name));

0 commit comments

Comments
 (0)