-
Notifications
You must be signed in to change notification settings - Fork 49
feat: show target of links in in "elan show" #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| use crate::errors::*; | ||
| use crate::notifications::Notification; | ||
| use dirs; | ||
| use json; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just |
||
| use std::cmp::Ord; | ||
| use std::env; | ||
| use std::ffi::OsString; | ||
|
|
@@ -11,7 +12,6 @@ use std::process::Command; | |
| use url::Url; | ||
| #[cfg(windows)] | ||
| use winreg; | ||
| use json; | ||
|
|
||
| use crate::raw; | ||
|
|
||
|
|
@@ -262,6 +262,25 @@ pub fn symlink_file(src: &Path, dest: &Path) -> Result<()> { | |
| .into()) | ||
| } | ||
|
|
||
| // If we are on unix, we expect reading the symlink to work, | ||
| // and so return Some. | ||
| #[cfg(unix)] | ||
| pub fn read_link(path: &Path) -> Result<Option<PathBuf>> { | ||
| Ok(Some(::std::fs::read_link(path).chain_err(|| { | ||
| ErrorKind::ReadingSymlink { | ||
| path: PathBuf::from(path), | ||
| } | ||
| })?)) | ||
| } | ||
|
|
||
| // If we are on windows, we don't attempt to read the symlink at all, | ||
| // and return None. This is not an error, but merely advice to the | ||
| // caller to not even attempt to show the symlink target. | ||
| #[cfg(windows)] | ||
| pub fn read_link(path: &Path) -> Result<Option<PathBuf>> { | ||
| Ok(None) | ||
| } | ||
|
|
||
| pub fn copy_dir(src: &Path, dest: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<()> { | ||
| notify_handler(Notification::CopyingDirectory(src, dest)); | ||
| raw::copy_dir(src, dest).chain_err(|| ErrorKind::CopyingDirectory { | ||
|
|
@@ -512,9 +531,10 @@ pub fn fetch_latest_release_json(url: &str, channel: &str, no_net: bool) -> Resu | |
| fetch_url(&url) | ||
| }?; | ||
|
|
||
| let releases = json::parse(&json) | ||
| .chain_err(|| format!("failed to parse release data: {}", url))?; | ||
| releases[channel][0]["name"].as_str() | ||
| let releases = | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also just |
||
| json::parse(&json).chain_err(|| format!("failed to parse release data: {}", url))?; | ||
| releases[channel][0]["name"] | ||
| .as_str() | ||
| .ok_or_else(|| format!("failed to parse release data: {}", url).into()) | ||
| .map(|s| s.to_string()) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,9 +140,10 @@ pub fn resolve_toolchain_desc_ext( | |
| utils::fetch_latest_release_json(uri, release, no_net) | ||
| } else { | ||
| if release == "beta" { | ||
| return Err(Error::from( | ||
| format!("channel 'beta' is not supported for custom origin '{}'", origin) | ||
| )); | ||
| return Err(Error::from(format!( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also just |
||
| "channel 'beta' is not supported for custom origin '{}'", | ||
| origin | ||
| ))); | ||
| } | ||
| utils::fetch_latest_release_tag(origin, no_net) | ||
| }; | ||
|
|
@@ -233,6 +234,9 @@ impl<'a> Toolchain<'a> { | |
| .map(|m| m.file_type().is_symlink()) | ||
| .unwrap_or(false) | ||
| } | ||
| pub fn symlink_target(&self) -> Result<Option<PathBuf>> { | ||
| Ok(utils::read_link(&self.path)?) | ||
| } | ||
| pub fn exists(&self) -> bool { | ||
| // HACK: linked toolchains are symlinks, and, contrary to what std docs | ||
| // lead me to believe `fs::metadata`, used by `is_directory` does not | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
mk_toolchain_label(&t, &default_tc, &resolved_default_tc)instead of just&t? I'm not sure about the potential for different decorations to overlap.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, seems fine