Skip to content

Commit

Permalink
fix: restore link functionality by checking for symlink instead of …
Browse files Browse the repository at this point in the history
…toolchain name
  • Loading branch information
Kha committed May 11, 2020
1 parent 031bf25 commit 34f9653
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 50 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Unreleased

## Changed

- Hopefully actually restore `elan toolchain link` functionality

# 0.10.1 - 2020-05-11

## Changed
Expand Down
12 changes: 3 additions & 9 deletions src/elan-cli/elan_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,8 @@ fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
let ref toolchain = m.value_of("toolchain").expect("");
let ref toolchain = try!(cfg.get_toolchain(toolchain, false));

let status = if !toolchain.is_custom() {
let status = if !toolchain.exists() || !toolchain.is_custom() {
Some(try!(toolchain.install_from_dist_if_not_installed()))
} else if !toolchain.exists() {
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
} else {
None
};
Expand All @@ -280,10 +278,8 @@ fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
for name in names {
let toolchain = try!(cfg.get_toolchain(name, false));

let status = if !toolchain.is_custom() {
let status = if !toolchain.exists() || !toolchain.is_custom() {
Some(try!(toolchain.install_from_dist(m.is_present("force"))))
} else if !toolchain.exists() {
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
} else {
None
};
Expand Down Expand Up @@ -429,10 +425,8 @@ fn override_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
let ref toolchain = m.value_of("toolchain").expect("");
let toolchain = try!(cfg.get_toolchain(toolchain, false));

let status = if !toolchain.is_custom() {
let status = if !toolchain.exists() || !toolchain.is_custom() {
Some(try!(toolchain.install_from_dist_if_not_installed()))
} else if !toolchain.exists() {
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
} else {
None
};
Expand Down
4 changes: 0 additions & 4 deletions src/elan-cli/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ r"DISCUSSION:
pub static TOOLCHAIN_LINK_HELP: &'static str =
r"DISCUSSION:
'toolchain' is the custom name to be assigned to the new toolchain.
Any name is permitted as long as it does not fully match an initial
substring of a standard release channel. For example, you can use
the names 'latest' or '2018-04-01' but you cannot use 'stable' or
'nightly'.
'path' specifies the directory where the binaries and libraries for
the custom toolchain can be found. For example, when used for
Expand Down
4 changes: 0 additions & 4 deletions src/elan-dist/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ error_chain! {
description("invalid toolchain name")
display("invalid toolchain name: '{}'", t)
}
InvalidCustomToolchainName(t: String) {
description("invalid custom toolchain name")
display("invalid custom toolchain name: '{}'", t)
}
ChecksumFailed {
url: String,
expected: String,
Expand Down
5 changes: 0 additions & 5 deletions src/elan/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ impl Cfg {
Ok(toolchain) => {
if toolchain.exists() {
Ok(Some((toolchain, reason)))
} else if toolchain.is_custom() {
// Strip the confusing NotADirectory error and only mention that the override
// toolchain is not installed.
Err(Error::from(reason_err))
.chain_err(|| ErrorKind::OverrideToolchainNotInstalled(name.to_string()))
} else {
try!(toolchain.install_from_dist(false));
Ok(Some((toolchain, reason)))
Expand Down
33 changes: 5 additions & 28 deletions src/elan/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ impl<'a> Toolchain<'a> {
// HACK: linked toolchains are symlinks, and, contrary to what std docs
// lead me to believe `fs::metadata`, used by `is_directory` does not
// seem to follow symlinks on windows.
let is_symlink = if cfg!(windows) {
self.is_symlink()
} else {
false
};
utils::is_directory(&self.path) || is_symlink
utils::is_directory(&self.path) || self.is_symlink()
}
pub fn is_custom(&self) -> bool {
assert!(self.exists());
self.is_symlink()
}
pub fn verify(&self) -> Result<()> {
Ok(try!(utils::assert_is_directory(&self.path)))
Expand All @@ -109,7 +108,6 @@ impl<'a> Toolchain<'a> {
Ok(try!(result))
}
fn install(&self, install_method: InstallMethod) -> Result<UpdateStatus> {
assert!(self.is_valid_install_method(install_method));
let exists = self.exists();
if exists {
(self.cfg.notify_handler)(Notification::UpdatingToolchain(&self.name));
Expand Down Expand Up @@ -137,7 +135,6 @@ impl<'a> Toolchain<'a> {
Ok(status)
}
fn install_if_not_installed(&self, install_method: InstallMethod) -> Result<UpdateStatus> {
assert!(self.is_valid_install_method(install_method));
(self.cfg.notify_handler)(Notification::LookingForToolchain(&self.name));
if !self.exists() {
Ok(try!(self.install(install_method)))
Expand All @@ -146,13 +143,6 @@ impl<'a> Toolchain<'a> {
Ok(UpdateStatus::Unchanged)
}
}
fn is_valid_install_method(&self, install_method: InstallMethod) -> bool {
match install_method {
InstallMethod::Copy(_) |
InstallMethod::Link(_) => self.is_custom(),
InstallMethod::Dist(..) => !self.is_custom()
}
}
fn update_hash(&self) -> Result<Option<PathBuf>> {
if self.is_symlink() {
Ok(None)
Expand Down Expand Up @@ -217,24 +207,11 @@ impl<'a> Toolchain<'a> {
self.download_cfg(),
false))
}
pub fn is_custom(&self) -> bool {
ToolchainDesc::from_str(&self.raw_name).is_err()
}
pub fn is_tracking(&self) -> bool {
ToolchainDesc::from_str(&self.raw_name).ok().map(|d| d.is_tracking()) == Some(true)
}

fn ensure_custom(&self) -> Result<()> {
if !self.is_custom() {
Err(ErrorKind::Dist(::elan_dist::ErrorKind::InvalidCustomToolchainName(self.name.to_string())).into())
} else {
Ok(())
}
}

pub fn install_from_dir(&self, src: &Path, link: bool) -> Result<()> {
try!(self.ensure_custom());

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

pathbuf.push("bin");
Expand Down

0 comments on commit 34f9653

Please sign in to comment.