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:
Jiahao XU 2022-07-23 18:33:30 +10:00
parent 7bdc720a9a
commit 79476e490b
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
2 changed files with 14 additions and 13 deletions

View file

@ -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.

View file

@ -241,13 +241,11 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
let desired_targets = get_desired_targets(&opts.targets);
// Compute install directory
let custom_install_path = opts.install_path.is_some();
let install_path: Arc<Path> = Arc::from(
get_install_path(opts.install_path.as_deref()).ok_or_else(|| {
error!("No viable install path found of specified, try `--install-path`");
miette!("No install path found or specified")
})?,
);
let (install_path, custom_install_path) = get_install_path(opts.install_path.as_deref());
let install_path: Arc<Path> = Arc::from(install_path.ok_or_else(|| {
error!("No viable install path found of specified, try `--install-path`");
miette!("No install path found or specified")
})?);
debug!("Using install path: {}", install_path.display());
// Create a temporary directory for downloads etc.