feat(rust): support $CARGO_HOME

get `.crates2.json` from `$CARGO_HOME` if present

Implements #70.
This commit is contained in:
steven-omaha
2024-04-04 21:38:55 +02:00
committed by GitHub
2 changed files with 17 additions and 2 deletions
@@ -86,8 +86,7 @@ impl Rust {
} }
fn get_crates_file() -> Result<PathBuf> { fn get_crates_file() -> Result<PathBuf> {
let mut result = crate::path::get_home_dir().context("getting home dir")?; let mut result = crate::path::get_cargo_home().context("getting cargo home dir")?;
result.push(".cargo");
result.push(".crates2.json"); result.push(".crates2.json");
Ok(result) Ok(result)
} }
+16
View File
@@ -34,6 +34,22 @@ pub(crate) fn get_pacdef_base_dir() -> Result<PathBuf> {
Ok(dir) 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. /// Get the path to the XDG config directory.
/// ///
/// # Errors /// # Errors