Replace std::env::home_dir() with home crate impl. (#9293)

* Import the `home` crate in `util/dir`.

* Replace uses of `env::home_dir()` with `home::home_dir()`.
  * `home` uses a 'correct' impl. on windows and the stdlib impl.
    of `::home_dir` otherwise.

* Reexport `home::home_dir` from `util/dir`.

* Bump `util/dir` to 0.1.2.
This commit is contained in:
Nick Sanders
2018-08-21 06:30:24 -07:00
committed by David
parent f230c719d8
commit 139a2b7b0d
6 changed files with 37 additions and 189 deletions

View File

@@ -15,14 +15,14 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Directory helper functions
use std::env;
use ::home_dir;
/// Replaces `$HOME` str with home directory path.
pub fn replace_home(base: &str, arg: &str) -> String {
// the $HOME directory on mac os should be `~/Library` or `~/Library/Application Support`
// We use an `if` so that we don't need to call `home_dir()` if not necessary.
let r = if arg.contains("$HOME") {
arg.replace("$HOME", env::home_dir().expect("$HOME isn't defined").to_str().unwrap())
arg.replace("$HOME", home_dir().expect("$HOME isn't defined").to_str().unwrap())
} else {
arg.to_owned()
};

View File

@@ -20,9 +20,10 @@
extern crate app_dirs;
extern crate ethereum_types;
extern crate journaldb;
extern crate home;
pub mod helpers;
use std::{env, fs};
use std::fs;
use std::path::{PathBuf, Path};
use ethereum_types::{H64, H256};
use journaldb::Algorithm;
@@ -31,6 +32,8 @@ use app_dirs::{AppInfo, get_app_root, AppDataType};
// re-export platform-specific functions
use platform::*;
pub use home::home_dir;
/// Platform-specific chains path for standard client - Windows only
#[cfg(target_os = "windows")] pub const CHAINS_PATH: &str = "$LOCAL/chains";
/// Platform-specific chains path for light client - Windows only
@@ -237,7 +240,7 @@ pub fn default_hypervisor_path() -> PathBuf {
/// Get home directory.
fn home() -> PathBuf {
env::home_dir().expect("Failed to get home dir")
home_dir().expect("Failed to get home dir")
}
/// Geth path