From c6432703f9a0f0a10d71d0962866186c8af7eedf Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 18 Jul 2017 17:23:33 -0700 Subject: [PATCH] Add cargo compat code --- Cargo.toml | 2 +- src/lib.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d2eed3e1de4..000046826a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.2.0" +version = "0.3.0" authors = [ "Brian Anderson " ] description = "Shared definitions of home directories" documentation = "https://docs.rs/home" diff --git a/src/lib.rs b/src/lib.rs index 49906084a5c..0917964b050 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -208,10 +208,22 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { .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 + } } }