mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-07 12:40:04 +00:00
Fix custom_install_path
detection
Installing to `CARGO_INSTALL_ROOT` or the local executable dir should be considered a custom installation path. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
7bdc720a9a
commit
79476e490b
2 changed files with 14 additions and 13 deletions
|
@ -172,22 +172,25 @@ pub async fn download_tar_based_and_visit<V: TarEntriesVisitor + Debug + Send +
|
|||
|
||||
/// Fetch install path from environment
|
||||
/// roughly follows <https://doc.rust-lang.org/cargo/commands/cargo-install.html#description>
|
||||
pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathBuf> {
|
||||
///
|
||||
/// Return (install_path, is_custom_install_path)
|
||||
pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> (Option<PathBuf>, bool) {
|
||||
// Command line override first first
|
||||
if let Some(p) = install_path {
|
||||
return Some(PathBuf::from(p.as_ref()));
|
||||
return (Some(PathBuf::from(p.as_ref())), true);
|
||||
}
|
||||
|
||||
// Environmental variables
|
||||
if let Ok(p) = std::env::var("CARGO_INSTALL_ROOT") {
|
||||
debug!("using CARGO_INSTALL_ROOT ({p})");
|
||||
let b = PathBuf::from(p);
|
||||
return Some(b.join("bin"));
|
||||
return (Some(b.join("bin")), true);
|
||||
}
|
||||
|
||||
if let Ok(p) = std::env::var("CARGO_HOME") {
|
||||
debug!("using CARGO_HOME ({p})");
|
||||
let b = PathBuf::from(p);
|
||||
return Some(b.join("bin"));
|
||||
return (Some(b.join("bin")), false);
|
||||
}
|
||||
|
||||
// Standard $HOME/.cargo/bin
|
||||
|
@ -196,7 +199,7 @@ pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathB
|
|||
if d.exists() {
|
||||
debug!("using $HOME/.cargo/bin");
|
||||
|
||||
return Some(d);
|
||||
return (Some(d), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,7 +210,7 @@ pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathB
|
|||
debug!("Fallback to {}", d.display());
|
||||
}
|
||||
|
||||
dir
|
||||
(dir, true)
|
||||
}
|
||||
|
||||
/// Atomically install a file.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue