mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Use home::cargo_home
in helpers::cargo_home
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
ad2d393be7
commit
5367b366d1
1 changed files with 1 additions and 25 deletions
|
@ -45,34 +45,10 @@ mod crate_name;
|
||||||
pub use crate_name::CrateName;
|
pub use crate_name::CrateName;
|
||||||
|
|
||||||
pub fn cargo_home() -> Result<&'static Path, io::Error> {
|
pub fn cargo_home() -> Result<&'static Path, io::Error> {
|
||||||
fn cargo_home_inner() -> Result<PathBuf, io::Error> {
|
|
||||||
if let Some(p) = env::var_os("CARGO_HOME") {
|
|
||||||
let p = PathBuf::from(p);
|
|
||||||
debug!("using CARGO_HOME ({})", p.display());
|
|
||||||
return Ok(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Standard $HOME/.cargo
|
|
||||||
if let Some(mut d) = dirs::home_dir() {
|
|
||||||
d.push(".cargo");
|
|
||||||
|
|
||||||
if d.exists() {
|
|
||||||
debug!("using $HOME/.cargo: {}", d.display());
|
|
||||||
|
|
||||||
return Ok(d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(io::Error::new(
|
|
||||||
io::ErrorKind::NotFound,
|
|
||||||
"Failed to detect cargo home",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
static CARGO_HOME: OnceCell<PathBuf> = OnceCell::new();
|
static CARGO_HOME: OnceCell<PathBuf> = OnceCell::new();
|
||||||
|
|
||||||
CARGO_HOME
|
CARGO_HOME
|
||||||
.get_or_try_init(cargo_home_inner)
|
.get_or_try_init(home::cargo_home)
|
||||||
.map(ops::Deref::deref)
|
.map(ops::Deref::deref)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue