Skip to content

Commit

Permalink
New default paths (openethereum#11641)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorot93 authored Apr 24, 2020
1 parent 4f3a128 commit 74e9293
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 41 deletions.
4 changes: 3 additions & 1 deletion accounts/ethstore/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ fn key_dir(location: &str, password: Option<Password>) -> Result<Box<dyn KeyDire
"geth-test" => RootDiskDirectory::create(dir::geth(true))?,
path if path.starts_with("parity") => {
let chain = path.split('-').nth(1).unwrap_or("ethereum");
let path = dir::parity(chain);
let mut path = dir::default_data_pathbuf();
path.push("keys");
path.push(chain);
RootDiskDirectory::create(path)?
},
path => RootDiskDirectory::create(path)?,
Expand Down
70 changes: 30 additions & 40 deletions util/dir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::path::{PathBuf, Path};
use ethereum_types::{H64, H256};
use journaldb::Algorithm;
use helpers::{replace_home, replace_home_and_local};
use app_dirs::{AppInfo, get_app_root, AppDataType};
use app_dirs::{AppInfo, get_app_root, data_root, AppDataType};
// re-export platform-specific functions
use platform::*;

Expand Down Expand Up @@ -226,16 +226,38 @@ impl DatabaseDirectories {
}
}

fn default_path(t: AppDataType) -> Option<PathBuf> {
let app_info = AppInfo { name: PRODUCT, author: AUTHOR };
let old_root = get_app_root(t, &app_info).ok()?;
if old_root.exists() {
return Some(old_root);
}

let mut root = data_root(t).ok()?;
root.push(if LOWERCASE { "openethereum" } else { "OpenEthereum" });
Some(root)
}

fn fallback_path() -> PathBuf {
let mut p = PathBuf::new();
p.push("$HOME");
p.push(".openethereum");
p
}

/// Default data path
pub fn default_data_pathbuf() -> PathBuf {
default_path(AppDataType::UserData).unwrap_or_else(fallback_path)
}

/// Default data path
pub fn default_data_path() -> String {
let app_info = AppInfo { name: PRODUCT, author: AUTHOR };
get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity".to_owned())
default_data_pathbuf().to_string_lossy().into_owned()
}

/// Default local path
pub fn default_local_path() -> String {
let app_info = AppInfo { name: PRODUCT, author: AUTHOR };
get_app_root(AppDataType::UserCache, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity".to_owned())
default_path(AppDataType::UserCache).unwrap_or_else(fallback_path).to_string_lossy().into_owned()
}

/// Default hypervisor path
Expand All @@ -259,29 +281,14 @@ pub fn geth(testnet: bool) -> PathBuf {
base
}

/// Parity path for specific chain
pub fn parity(chain: &str) -> PathBuf {
let mut base = parity_base();
base.push(chain);
base
}

#[cfg(target_os = "macos")]
mod platform {
use std::path::PathBuf;
pub const LOWERCASE: bool = false;
pub const AUTHOR: &str = "Parity";
pub const PRODUCT: &str = "io.parity.ethereum";
pub const PRODUCT_HYPERVISOR: &str = "io.parity.ethereum-updates";

pub fn parity_base() -> PathBuf {
let mut home = super::home();
home.push("Library");
home.push("Application Support");
home.push("io.parity.ethereum");
home.push("keys");
home
}

pub fn geth_base() -> PathBuf {
let mut home = super::home();
home.push("Library");
Expand All @@ -293,20 +300,11 @@ mod platform {
#[cfg(windows)]
mod platform {
use std::path::PathBuf;
pub const LOWERCASE: bool = false;
pub const AUTHOR: &str = "Parity";
pub const PRODUCT: &str = "Ethereum";
pub const PRODUCT_HYPERVISOR: &str = "EthereumUpdates";

pub fn parity_base() -> PathBuf {
let mut home = super::home();
home.push("AppData");
home.push("Roaming");
home.push("Parity");
home.push("Ethereum");
home.push("keys");
home
}

pub fn geth_base() -> PathBuf {
let mut home = super::home();
home.push("AppData");
Expand All @@ -319,19 +317,11 @@ mod platform {
#[cfg(not(any(target_os = "macos", windows)))]
mod platform {
use std::path::PathBuf;
pub const LOWERCASE: bool = true;
pub const AUTHOR: &str = "parity";
pub const PRODUCT: &str = "io.parity.ethereum";
pub const PRODUCT_HYPERVISOR: &str = "io.parity.ethereum-updates";

pub fn parity_base() -> PathBuf {
let mut home = super::home();
home.push(".local");
home.push("share");
home.push("io.parity.ethereum");
home.push("keys");
home
}

pub fn geth_base() -> PathBuf {
let mut home = super::home();
home.push(".ethereum");
Expand Down

0 comments on commit 74e9293

Please sign in to comment.