Skip to content

Commit 18eabcc

Browse files
committed
Remove is_valid_install_method
This is now enforced by the type system rather than asserts.
1 parent 56e2018 commit 18eabcc

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/install.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use crate::dist::temp;
99
use crate::dist::Notification;
1010
use crate::errors::Result;
1111
use crate::notifications::Notification as RootNotification;
12-
use crate::toolchain::{Toolchain, UpdateStatus};
12+
use crate::toolchain::{CustomToolchain, DistributableToolchain, Toolchain, UpdateStatus};
1313
use crate::utils::utils;
1414
use std::path::Path;
1515

1616
#[derive(Copy, Clone)]
1717
pub enum InstallMethod<'a> {
18-
Copy(&'a Path),
19-
Link(&'a Path),
20-
Installer(&'a Path, &'a temp::Cfg),
18+
Copy(&'a Path, &'a CustomToolchain<'a>),
19+
Link(&'a Path, &'a CustomToolchain<'a>),
20+
Installer(&'a Path, &'a temp::Cfg, &'a CustomToolchain<'a>),
2121
// bool is whether to force an update
2222
Dist(
2323
&'a dist::ToolchainDesc,
@@ -36,13 +36,13 @@ pub enum InstallMethod<'a> {
3636
&'a [&'a str],
3737
// Extra targets to install from dist
3838
&'a [&'a str],
39+
&'a DistributableToolchain<'a>,
3940
),
4041
}
4142

4243
impl<'a> InstallMethod<'a> {
4344
// Install a toolchain
4445
pub fn install(&self, toolchain: &Toolchain<'a>) -> Result<UpdateStatus> {
45-
assert!(toolchain.is_valid_install_method(*self));
4646
let previous_version = if toolchain.exists() {
4747
Some(toolchain.rustc_version())
4848
} else {
@@ -94,15 +94,15 @@ impl<'a> InstallMethod<'a> {
9494
}
9595

9696
match self {
97-
InstallMethod::Copy(src) => {
97+
InstallMethod::Copy(src, ..) => {
9898
utils::copy_dir(src, path, notify_handler)?;
9999
Ok(true)
100100
}
101-
InstallMethod::Link(src) => {
101+
InstallMethod::Link(src, ..) => {
102102
utils::symlink_dir(src, &path, notify_handler)?;
103103
Ok(true)
104104
}
105-
InstallMethod::Installer(src, temp_cfg) => {
105+
InstallMethod::Installer(src, temp_cfg, ..) => {
106106
InstallMethod::tar_gz(src, path, &temp_cfg, notify_handler)?;
107107
Ok(true)
108108
}
@@ -117,6 +117,7 @@ impl<'a> InstallMethod<'a> {
117117
old_date,
118118
components,
119119
targets,
120+
..,
120121
) => {
121122
let prefix = &InstallPrefix::from(path.to_owned());
122123
let maybe_new_hash = dist::update_from_dist(

src/toolchain.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,6 @@ impl<'a> Toolchain<'a> {
139139
Ok(())
140140
}
141141

142-
// Custom and Distributable. Installed and not installed (because of install_from_dist_if_not_installed) Goes away?
143-
// Or perhaps a trait.
144-
pub fn is_valid_install_method(&self, install_method: InstallMethod<'_>) -> bool {
145-
match install_method {
146-
InstallMethod::Copy(_) | InstallMethod::Link(_) | InstallMethod::Installer(..) => {
147-
self.is_custom()
148-
}
149-
InstallMethod::Dist(..) => !self.is_custom(),
150-
}
151-
}
152-
153142
// XXX: Move to Config with a notify handler parameter
154143
fn download_cfg(&self) -> DownloadCfg<'_> {
155144
DownloadCfg {
@@ -186,6 +175,7 @@ impl<'a> Toolchain<'a> {
186175
pub fn install_from_installers(&self, installers: &[&OsStr]) -> Result<()> {
187176
self.ensure_custom()?;
188177

178+
let custom = CustomToolchain::new(&self)?;
189179
self.remove()?;
190180

191181
// FIXME: This should do all downloads first, then do
@@ -214,15 +204,17 @@ impl<'a> Toolchain<'a> {
214204
utils::download_file(&url, &local_installer, None, &|n| {
215205
(self.cfg.notify_handler)(n.into())
216206
})?;
217-
InstallMethod::Installer(&local_installer, &self.cfg.temp_cfg).install(&self)?;
207+
InstallMethod::Installer(&local_installer, &self.cfg.temp_cfg, &custom)
208+
.install(&self)?;
218209
} else {
219210
// If installer is a filename
220211

221212
// No need to download
222213
let local_installer = Path::new(installer);
223214

224215
// Install from file
225-
InstallMethod::Installer(&local_installer, &self.cfg.temp_cfg).install(&self)?;
216+
InstallMethod::Installer(&local_installer, &self.cfg.temp_cfg, &custom)
217+
.install(&self)?;
226218
}
227219
}
228220

@@ -232,6 +224,7 @@ impl<'a> Toolchain<'a> {
232224
// Custom only. Not installed only.
233225
pub fn install_from_dir(&self, src: &Path, link: bool) -> Result<()> {
234226
self.ensure_custom()?;
227+
let custom = CustomToolchain::new(&self)?;
235228

236229
let mut pathbuf = PathBuf::from(src);
237230

@@ -244,9 +237,9 @@ impl<'a> Toolchain<'a> {
244237
utils::assert_is_file(&pathbuf)?;
245238

246239
if link {
247-
InstallMethod::Link(&utils::to_absolute(src)?).install(&self)?;
240+
InstallMethod::Link(&utils::to_absolute(src)?, &custom).install(&self)?;
248241
} else {
249-
InstallMethod::Copy(src).install(&self)?;
242+
InstallMethod::Copy(src, &custom).install(&self)?;
250243
}
251244

252245
Ok(())
@@ -731,6 +724,7 @@ impl<'a> DistributableToolchain<'a> {
731724
old_date.as_ref().map(|s| &**s),
732725
components,
733726
targets,
727+
&self,
734728
)
735729
.install(&self.0)
736730
}
@@ -751,6 +745,7 @@ impl<'a> DistributableToolchain<'a> {
751745
None,
752746
&[],
753747
&[],
748+
&self,
754749
)
755750
.install(&self.0)?)
756751
} else {

0 commit comments

Comments
 (0)