mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 04:58:42 +00:00
Mod get_install_path
to ret Arc<Path>
instead of PathBuf
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
5620810c55
commit
5ea66574c3
2 changed files with 7 additions and 6 deletions
|
@ -3,6 +3,7 @@ use std::fs;
|
|||
use std::io;
|
||||
use std::ops;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use bytes::Bytes;
|
||||
use cargo_toml::Manifest;
|
||||
|
@ -174,17 +175,17 @@ pub async fn download_tar_based_and_visit<V: TarEntriesVisitor + Debug + Send +
|
|||
/// roughly follows <https://doc.rust-lang.org/cargo/commands/cargo-install.html#description>
|
||||
///
|
||||
/// Return (install_path, is_custom_install_path)
|
||||
pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> (Option<PathBuf>, bool) {
|
||||
pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> (Option<Arc<Path>>, bool) {
|
||||
// Command line override first first
|
||||
if let Some(p) = install_path {
|
||||
return (Some(PathBuf::from(p.as_ref())), true);
|
||||
return (Some(Arc::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")), true);
|
||||
return (Some(Arc::from(b.join("bin"))), true);
|
||||
}
|
||||
|
||||
if let Ok(p) = cargo_home() {
|
||||
|
@ -199,7 +200,7 @@ pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> (Option<Path
|
|||
debug!("Fallback to {}", d.display());
|
||||
}
|
||||
|
||||
(dir, true)
|
||||
(dir.map(Arc::from), true)
|
||||
}
|
||||
|
||||
/// Atomically install a file.
|
||||
|
|
|
@ -242,10 +242,10 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
|
|||
|
||||
// Compute install directory
|
||||
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(|| {
|
||||
let install_path = 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.
|
||||
|
|
Loading…
Add table
Reference in a new issue