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

Commit

Permalink
Fix env::home_dir() deprecation warning.
Browse files Browse the repository at this point in the history
* Import the `dirs` crate in `util/dir`.

* Replace uses of `env::home_dir()` with `dirs::home_dir()`.

* Reexport `dirs::home_dir`.

* Continue to use `std::env::home_dir` on Android, suppressing
  deprecation warnings.
  • Loading branch information
c0gent committed Aug 5, 2018
1 parent 25604dc commit 3e0f83b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
33 changes: 22 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions parity/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
use semver::{Version, SemVerError};
use std::collections::*;
use std::fs::{self, File, create_dir_all};
use std::env;
use std::io;
use std::io::{Read, Write};
use std::path::{PathBuf, Path};
use dir::{DatabaseDirectories, default_data_path};
#[cfg_attr(target_os="android", allow(deprecated))]
use dir::{DatabaseDirectories, default_data_path, home_dir};
use dir::helpers::replace_home;
use journaldb::Algorithm;

Expand Down Expand Up @@ -201,7 +201,7 @@ fn upgrade_user_defaults(dirs: &DatabaseDirectories) {
}

pub fn upgrade_data_paths(base_path: &str, dirs: &DatabaseDirectories, pruning: Algorithm) {
if env::home_dir().is_none() {
if home_dir().is_none() {
return;
}

Expand Down
1 change: 1 addition & 0 deletions util/dir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ license = "GPL3"
ethereum-types = "0.3"
journaldb = { path = "../journaldb" }
app_dirs = { git = "https://github.com/paritytech/app-dirs-rs" }
dirs = "1.0"
6 changes: 4 additions & 2 deletions util/dir/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

//! Directory helper functions
use std::env;
#[cfg_attr(target_os="android", allow(deprecated))]
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())
#[cfg_attr(target_os="android", allow(deprecated))]
arg.replace("$HOME", home_dir().expect("$HOME isn't defined").to_str().unwrap())
} else {
arg.to_owned()
};
Expand Down
12 changes: 10 additions & 2 deletions util/dir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
extern crate app_dirs;
extern crate ethereum_types;
extern crate journaldb;
extern crate dirs;

pub mod helpers;
use std::{env, fs};
use std::fs;
use std::path::{PathBuf, Path};
use ethereum_types::{H64, H256};
use journaldb::Algorithm;
Expand All @@ -31,6 +32,13 @@ use app_dirs::{AppInfo, get_app_root, AppDataType};
// re-export platform-specific functions
use platform::*;

#[cfg(not(target_os="android"))]
pub use dirs::home_dir;
#[cfg(target_os="android")]
#[allow(deprecated)]
pub use std::env::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
Expand Down Expand Up @@ -237,7 +245,7 @@ pub fn default_hypervisor_path() -> PathBuf {

/// Get home directory.
fn home() -> PathBuf {
env::home_dir().expect("Failed to get home dir")
dirs::home_dir().expect("Failed to get home dir")
}

/// Geth path
Expand Down

0 comments on commit 3e0f83b

Please sign in to comment.