Skip to content

Commit

Permalink
Add cargo compat code
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Jul 19, 2017
1 parent 759a15b commit c643270
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "home"
version = "0.2.0"
version = "0.3.0"
authors = [ "Brian Anderson <andersrb@gmail.com>" ]
description = "Shared definitions of home directories"
documentation = "https://docs.rs/home"
Expand Down
14 changes: 13 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,22 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result<PathBuf> {
.ok_or(io::Error::new(io::ErrorKind::Other, "couldn't find home dir"));
let user_home = home_dir.map(|p| p.join(".cargo"));

// Compatibility with old cargo that used the std definition of home_dir
let compat_home_dir = ::std::env::home_dir();
let compat_user_home = compat_home_dir.map(|p| p.join(".cargo"));

if let Some(p) = env_cargo_home {
Ok(p)
} else {
user_home
if let Some(d) = compat_user_home {
if d.exists() {
Ok(d)
} else {
user_home
}
} else {
user_home
}
}
}

Expand Down

0 comments on commit c643270

Please sign in to comment.