get .crates2.json from $CARGO_HOME if present

This commit is contained in:
Dan Bluhm Hansen
2024-04-04 19:35:40 +02:00
parent 8cc5365070
commit 45af4a251e
2 changed files with 17 additions and 2 deletions
@@ -86,8 +86,7 @@ impl Rust {
}
fn get_crates_file() -> Result<PathBuf> {
let mut result = crate::path::get_home_dir().context("getting home dir")?;
result.push(".cargo");
let mut result = crate::path::get_cargo_home().context("getting cargo home dir")?;
result.push(".crates2.json");
Ok(result)
}
+16
View File
@@ -34,6 +34,22 @@ pub(crate) fn get_pacdef_base_dir() -> Result<PathBuf> {
Ok(dir)
}
/// Get the path to the cargo home directory.
///
/// # Errors
///
/// This function will return an error if neither the `$CARGO_HOME` nor
/// the `$HOME` environment variables are set.
pub(crate) fn get_cargo_home() -> Result<PathBuf> {
if let Ok(config) = env::var("CARGO_HOME") {
Ok(config.into())
} else {
let mut config = get_home_dir().context("falling back to $HOME/.cargo")?;
config.push(".cargo");
Ok(config)
}
}
/// Get the path to the XDG config directory.
///
/// # Errors