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

Fix env::home_dir() deprecation warning. #9281

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions parity/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
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};
use dir::{DatabaseDirectories, default_data_path, home_dir};
use dir::helpers::replace_home;
use journaldb::Algorithm;

Expand Down Expand Up @@ -201,7 +200,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
3 changes: 2 additions & 1 deletion util/dir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "dir"
version = "0.1.1"
version = "0.1.2"
authors = ["Parity Technologies <admin@parity.io>"]
license = "GPL3"

[dependencies]
ethereum-types = "0.3"
journaldb = { path = "../journaldb" }
app_dirs = { git = "https://github.com/paritytech/app-dirs-rs" }
dirs = "1.0"
5 changes: 3 additions & 2 deletions util/dir/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
// 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())
#[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
10 changes: 8 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,11 @@ 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")]
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 +243,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