Skip to content

Commit

Permalink
fix: updating channels from non-default repos
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
Kha committed Apr 28, 2021
1 parent dbabc92 commit 32b6d0d
Showing 3 changed files with 21 additions and 8 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Unreleased

## Changed

- Fix updating channels from non-default repos (e.g. `leanprover/lean4:nightly`)
This change affects the store location of such toolchains, so you will have to re-install them first.
```sh
$ elan toolchain uninstall leanprover-lean4-nightly
$ elan toolchain install leanprover/lean4:nightly
```

# 1.0.0 - 2021-04-17

- Move to `leanprover/elan`
5 changes: 5 additions & 0 deletions src/elan/config.rs
Original file line number Diff line number Diff line change
@@ -278,11 +278,16 @@ impl Cfg {
}

pub fn list_toolchains(&self) -> Result<Vec<String>> {
// de-sanitize toolchain file names (best effort...)
fn insane(s: String) -> String {
s.replace("---", ":").replace("--", "/")
}
if utils::is_directory(&self.toolchains_dir) {
let mut toolchains: Vec<_> = try!(utils::read_dir("toolchains", &self.toolchains_dir))
.filter_map(io::Result::ok)
.filter(|e| e.file_type().map(|f| !f.is_file()).unwrap_or(false))
.filter_map(|e| e.file_name().into_string().ok())
.map(insane)
.collect();

utils::toolchain_sort(&mut toolchains);
13 changes: 5 additions & 8 deletions src/elan/toolchain.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ use regex::Regex;
pub struct Toolchain<'a> {
cfg: &'a Cfg,
name: String,
raw_name: String,
path: PathBuf,
telemetry: telemetry::Telemetry,
dist_handler: Box<Fn(elan_dist::Notification) + 'a>,
@@ -48,15 +47,13 @@ impl<'a> Toolchain<'a> {
pub fn from(cfg: &'a Cfg, name: &str) -> Result<Self> {
//We need to replace ":" and "/" with "-" in the toolchain name in order to make a name which is a valid
//name for a directory.
let re = Regex::new(r"[:/]").unwrap();
let sane_name = re.replace_all(name, "-");
let dir_name = name.replace("/", "--").replace(":", "---");

let path = cfg.toolchains_dir.join(&sane_name[..]);
let path = cfg.toolchains_dir.join(&dir_name[..]);

Ok(Toolchain {
cfg: cfg,
name: sane_name.to_string(),
raw_name: name.to_owned(),
name: name.to_owned(),
path: path.clone(),
telemetry: Telemetry::new(cfg.elan_dir.join("telemetry")),
dist_handler: Box::new(move |n| {
@@ -68,7 +65,7 @@ impl<'a> Toolchain<'a> {
&self.name
}
pub fn desc(&self) -> Result<ToolchainDesc> {
Ok(try!(ToolchainDesc::from_str(&self.raw_name)))
Ok(try!(ToolchainDesc::from_str(&self.name)))
}
pub fn path(&self) -> &Path {
&self.path
@@ -208,7 +205,7 @@ impl<'a> Toolchain<'a> {
false))
}
pub fn is_tracking(&self) -> bool {
ToolchainDesc::from_str(&self.raw_name).ok().map(|d| d.is_tracking()) == Some(true)
ToolchainDesc::from_str(&self.name).ok().map(|d| d.is_tracking()) == Some(true)
}

pub fn install_from_dir(&self, src: &Path, link: bool) -> Result<()> {

0 comments on commit 32b6d0d

Please sign in to comment.