Skip to content

Commit

Permalink
stop cargo_home from unnecessarily getting $HOME
Browse files Browse the repository at this point in the history
also prevent unnecessary UTF8 compliance assertion for $CARGO_HOME
  • Loading branch information
chrismooredev committed Dec 3, 2020
1 parent 336011a commit ff1e158
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ struct CargoConfig {
source: HashMap<String, Source>,
}

/// Returns the user's configured, or default, cargo home directory.
fn cargo_home() -> Result<PathBuf> {
let default_cargo_home = dirs::home_dir()
.map(|x| x.join(".cargo"))
.chain_err(|| ErrorKind::ReadHomeDirFailure)?;
let cargo_home = std::env::var("CARGO_HOME")
.map(PathBuf::from)
.unwrap_or(default_cargo_home);
Ok(cargo_home)
// use $HOME/.cargo if no $CARGO_HOME or $CARGO_HOME has bad UTF8
match std::env::var_os("CARGO_HOME") {
Some(cargo_home) => Ok(cargo_home.into()),
None => {
let userhome = dirs::home_dir().chain_err(|| ErrorKind::ReadHomeDirFailure)?;
Ok(userhome.join(".cargo"))
}
}
}

/// Find the URL of a registry
Expand Down

0 comments on commit ff1e158

Please sign in to comment.