Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 23d0473

Browse files
committed
Replace std::env::home_dir with dirs::home_dir
`std::env::home_dir` is deprecated but will probably take a while until it is deprecated on stable. For more info see rust-lang/rust#51656
1 parent 8d171a3 commit 23d0473

File tree

7 files changed

+51
-30
lines changed

7 files changed

+51
-30
lines changed

Cargo.lock

Lines changed: 22 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parity/upgrade.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
//! Parity upgrade logic
1818
1919
use semver::{Version, SemVerError};
20-
use std::collections::*;
20+
use std::collections::HashMap;
2121
use std::fs::{self, File, create_dir_all};
22-
use std::env;
2322
use std::io;
2423
use std::io::{Read, Write};
2524
use std::path::{PathBuf, Path};
26-
use dir::{DatabaseDirectories, default_data_path};
25+
use dir::{DatabaseDirectories, default_data_path, home_dir};
2726
use dir::helpers::replace_home;
2827
use journaldb::Algorithm;
2928

@@ -106,7 +105,7 @@ fn with_locked_version<F>(db_path: Option<&str>, script: F) -> Result<usize, Err
106105
where F: Fn(&Version) -> Result<usize, Error>
107106
{
108107
let mut path = db_path.map_or({
109-
let mut path = env::home_dir().expect("Applications should have a home dir");
108+
let mut path = home_dir().expect("Applications should have a home dir");
110109
path.push(".parity");
111110
path
112111
}, PathBuf::from);

util/dir/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[package]
22
name = "dir"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Parity Technologies <[email protected]>"]
5+
license = "GPL3"
56

67
[dependencies]
78
ethereum-types = "0.3"
89
journaldb = { path = "../journaldb" }
910
app_dirs = { git = "https://github.com/paritytech/app-dirs-rs" }
11+
dirs = "1.0.2"

util/dir/src/helpers.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
1616

1717
//! Directory helper functions
18-
use std::env;
1918
2019
/// Replaces `$HOME` str with home directory path.
2120
pub fn replace_home(base: &str, arg: &str) -> String {
2221
// the $HOME directory on mac os should be `~/Library` or `~/Library/Application Support`
23-
let r = arg.replace("$HOME", env::home_dir().unwrap().to_str().unwrap());
22+
let r = arg.replace("$HOME", ::dirs::home_dir().unwrap().to_str().unwrap());
2423
let r = r.replace("$BASE", base);
2524
r.replace("/", &::std::path::MAIN_SEPARATOR.to_string())
2625
}

util/dir/src/lib.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818

1919
//! Dir utilities for platform-specific operations
2020
extern crate app_dirs;
21+
extern crate dirs;
2122
extern crate ethereum_types;
2223
extern crate journaldb;
2324

2425
pub mod helpers;
25-
use std::{env, fs};
26+
use std::fs;
2627
use std::path::{PathBuf, Path};
2728
use ethereum_types::{H64, H256};
2829
use journaldb::Algorithm;
@@ -31,19 +32,21 @@ use app_dirs::{AppInfo, get_app_root, AppDataType};
3132
// re-export platform-specific functions
3233
use platform::*;
3334

35+
pub use dirs::home_dir;
36+
3437
/// Platform-specific chains path - Windows only
35-
#[cfg(target_os = "windows")] pub const CHAINS_PATH: &'static str = "$LOCAL/chains";
38+
#[cfg(target_os = "windows")] pub const CHAINS_PATH: &str = "$LOCAL/chains";
3639
/// Platform-specific chains path
37-
#[cfg(not(target_os = "windows"))] pub const CHAINS_PATH: &'static str = "$BASE/chains";
40+
#[cfg(not(target_os = "windows"))] pub const CHAINS_PATH: &str = "$BASE/chains";
3841

3942
/// Platform-specific cache path - Windows only
40-
#[cfg(target_os = "windows")] pub const CACHE_PATH: &'static str = "$LOCAL/cache";
43+
#[cfg(target_os = "windows")] pub const CACHE_PATH: &str = "$LOCAL/cache";
4144
/// Platform-specific cache path
42-
#[cfg(not(target_os = "windows"))] pub const CACHE_PATH: &'static str = "$BASE/cache";
45+
#[cfg(not(target_os = "windows"))] pub const CACHE_PATH: &str = "$BASE/cache";
4346

4447
// this const is irrelevent cause we do have migrations now,
4548
// but we still use it for backwards compatibility
46-
const LEGACY_CLIENT_DB_VER_STR: &'static str = "5.3";
49+
const LEGACY_CLIENT_DB_VER_STR: &str = "5.3";
4750

4851
#[derive(Debug, PartialEq)]
4952
/// Parity local data directories
@@ -239,7 +242,7 @@ pub fn default_hypervisor_path() -> PathBuf {
239242

240243
/// Get home directory.
241244
fn home() -> PathBuf {
242-
env::home_dir().expect("Failed to get home dir")
245+
dirs::home_dir().expect("Failed to get home dir")
243246
}
244247

245248
/// Geth path
@@ -312,9 +315,9 @@ mod platform {
312315
#[cfg(not(any(target_os = "macos", windows)))]
313316
mod platform {
314317
use std::path::PathBuf;
315-
pub const AUTHOR: &'static str = "parity";
316-
pub const PRODUCT: &'static str = "io.parity.ethereum";
317-
pub const PRODUCT_HYPERVISOR: &'static str = "io.parity.ethereum-updates";
318+
pub const AUTHOR: &str = "parity";
319+
pub const PRODUCT: &str = "io.parity.ethereum";
320+
pub const PRODUCT_HYPERVISOR: &str = "io.parity.ethereum-updates";
318321

319322
pub fn parity_base() -> PathBuf {
320323
let mut home = super::home();

util/path/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "path"
3-
version = "0.1.0"
4-
authors = ["debris <[email protected]>"]
3+
version = "0.1.1"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
license = "GPL3"
56

67
[dependencies]
8+
dirs = "1.0.2"

util/path/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
1616

1717
//! Path utilities
18+
extern crate dirs;
19+
1820
use std::path::Path;
1921
use std::path::PathBuf;
2022

2123
#[cfg(target_os = "macos")]
2224
/// Get the config path for application `name`.
2325
/// `name` should be capitalized, e.g. `"Ethereum"`, `"Parity"`.
2426
pub fn config_path(name: &str) -> PathBuf {
25-
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
27+
let mut home = dirs::home_dir().expect("Failed to get home dir");
2628
home.push("Library");
2729
home.push(name);
2830
home
@@ -32,7 +34,7 @@ pub fn config_path(name: &str) -> PathBuf {
3234
/// Get the config path for application `name`.
3335
/// `name` should be capitalized, e.g. `"Ethereum"`, `"Parity"`.
3436
pub fn config_path(name: &str) -> PathBuf {
35-
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
37+
let mut home = dirs::home_dir().expect("Failed to get home dir");
3638
home.push("AppData");
3739
home.push("Roaming");
3840
home.push(name);
@@ -43,7 +45,7 @@ pub fn config_path(name: &str) -> PathBuf {
4345
/// Get the config path for application `name`.
4446
/// `name` should be capitalized, e.g. `"Ethereum"`, `"Parity"`.
4547
pub fn config_path(name: &str) -> PathBuf {
46-
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
48+
let mut home = dirs::home_dir().expect("Failed to get home dir");
4749
home.push(format!(".{}", name.to_lowercase()));
4850
home
4951
}

0 commit comments

Comments
 (0)