Fix #6209 - introduce standalone dir crate

* created the dir crate in util
* moved code from ethstore/src/dir/paths.rs to dir crate
* rename dir module in ethstore to accounts_dir to distinguish it
  from the dir crate
* changes after @tomusdrw on #6952
This commit is contained in:
Nicolas Ochem 2017-12-24 00:34:43 -08:00
parent 82340c058a
commit 2e12a2db50
31 changed files with 171 additions and 141 deletions

12
Cargo.lock generated
View File

@ -359,6 +359,15 @@ name = "difference"
version = "1.0.0" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "dir"
version = "0.1.0"
dependencies = [
"app_dirs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ethcore-bigint 0.2.1",
"journaldb 0.1.0",
]
[[package]] [[package]]
name = "docopt" name = "docopt"
version = "0.8.1" version = "0.8.1"
@ -784,6 +793,7 @@ dependencies = [
name = "ethstore" name = "ethstore"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"dir 0.1.0",
"ethcore-bigint 0.2.1", "ethcore-bigint 0.2.1",
"ethcrypto 0.1.0", "ethcrypto 0.1.0",
"ethkey 0.3.0", "ethkey 0.3.0",
@ -808,6 +818,7 @@ dependencies = [
name = "ethstore-cli" name = "ethstore-cli"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dir 0.1.0",
"docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ethstore 0.2.0", "ethstore 0.2.0",
"num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1881,6 +1892,7 @@ dependencies = [
"clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ctrlc 1.1.1 (git+https://github.com/paritytech/rust-ctrlc.git)", "ctrlc 1.1.1 (git+https://github.com/paritytech/rust-ctrlc.git)",
"daemonize 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "daemonize 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"dir 0.1.0",
"docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ethcore 1.9.0", "ethcore 1.9.0",

View File

@ -58,6 +58,7 @@ parity-updater = { path = "updater" }
parity-version = { path = "util/version" } parity-version = { path = "util/version" }
parity-whisper = { path = "whisper" } parity-whisper = { path = "whisper" }
path = { path = "util/path" } path = { path = "util/path" }
dir = { path = "util/dir" }
panic_hook = { path = "panic_hook" } panic_hook = { path = "panic_hook" }
keccak-hash = { path = "util/hash" } keccak-hash = { path = "util/hash" }
migration = { path = "util/migration" } migration = { path = "util/migration" }

View File

@ -28,7 +28,7 @@ use ethstore::{
SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore, SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore,
random_string, SecretVaultRef, StoreAccountRef, OpaqueSecret, random_string, SecretVaultRef, StoreAccountRef, OpaqueSecret,
}; };
use ethstore::dir::MemoryDirectory; use ethstore::accounts_dir::MemoryDirectory;
use ethstore::ethkey::{Address, Message, Public, Secret, Random, Generator}; use ethstore::ethkey::{Address, Message, Public, Secret, Random, Generator};
use ethjson::misc::AccountMeta; use ethjson::misc::AccountMeta;
use hardware_wallet::{Error as HardwareError, HardwareWalletManager, KeyPath, TransactionInfo}; use hardware_wallet::{Error as HardwareError, HardwareWalletManager, KeyPath, TransactionInfo};

View File

@ -19,6 +19,7 @@ itertools = "0.5"
parking_lot = "0.4" parking_lot = "0.4"
ethcrypto = { path = "../ethcrypto" } ethcrypto = { path = "../ethcrypto" }
ethcore-bigint = { path = "../util/bigint" } ethcore-bigint = { path = "../util/bigint" }
dir = { path = "../util/dir" }
smallvec = "0.4" smallvec = "0.4"
parity-wordlist = "1.0" parity-wordlist = "1.0"
tempdir = "0.3" tempdir = "0.3"

View File

@ -11,6 +11,7 @@ serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
parking_lot = "0.4" parking_lot = "0.4"
ethstore = { path = "../" } ethstore = { path = "../" }
dir = { path = '../../util/dir' }
panic_hook = { path = "../../panic_hook" } panic_hook = { path = "../../panic_hook" }
[[bin]] [[bin]]

View File

@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
extern crate dir;
extern crate docopt; extern crate docopt;
extern crate ethstore; extern crate ethstore;
extern crate num_cpus; extern crate num_cpus;
@ -30,7 +31,7 @@ use std::io::Read;
use std::{env, process, fs, fmt}; use std::{env, process, fs, fmt};
use docopt::Docopt; use docopt::Docopt;
use ethstore::dir::{paths, KeyDirectory, RootDiskDirectory}; use ethstore::accounts_dir::{KeyDirectory, RootDiskDirectory};
use ethstore::ethkey::Address; use ethstore::ethkey::Address;
use ethstore::{EthStore, SimpleSecretStore, SecretStore, import_accounts, PresaleWallet, SecretVaultRef, StoreAccountRef}; use ethstore::{EthStore, SimpleSecretStore, SecretStore, import_accounts, PresaleWallet, SecretVaultRef, StoreAccountRef};
@ -157,11 +158,11 @@ fn main() {
fn key_dir(location: &str) -> Result<Box<KeyDirectory>, Error> { fn key_dir(location: &str) -> Result<Box<KeyDirectory>, Error> {
let dir: Box<KeyDirectory> = match location { let dir: Box<KeyDirectory> = match location {
"geth" => Box::new(RootDiskDirectory::create(paths::geth(false))?), "geth" => Box::new(RootDiskDirectory::create(dir::geth(false))?),
"geth-test" => Box::new(RootDiskDirectory::create(paths::geth(true))?), "geth-test" => Box::new(RootDiskDirectory::create(dir::geth(true))?),
path if path.starts_with("parity") => { path if path.starts_with("parity") => {
let chain = path.split('-').nth(1).unwrap_or("ethereum"); let chain = path.split('-').nth(1).unwrap_or("ethereum");
let path = paths::parity(chain); let path = dir::parity(chain);
Box::new(RootDiskDirectory::create(path)?) Box::new(RootDiskDirectory::create(path)?)
}, },
path => Box::new(RootDiskDirectory::create(path)?), path => Box::new(RootDiskDirectory::create(path)?),

View File

@ -290,8 +290,7 @@ mod test {
extern crate tempdir; extern crate tempdir;
use std::{env, fs}; use std::{env, fs};
use super::RootDiskDirectory; use super::{KeyDirectory, RootDiskDirectory, VaultKey};
use dir::{KeyDirectory, VaultKey};
use account::SafeAccount; use account::SafeAccount;
use ethkey::{Random, Generator}; use ethkey::{Random, Generator};
use self::tempdir::TempDir; use self::tempdir::TempDir;

View File

@ -22,7 +22,6 @@ use {SafeAccount, Error};
mod disk; mod disk;
mod memory; mod memory;
mod vault; mod vault;
pub mod paths;
/// `VaultKeyDirectory::set_key` error /// `VaultKeyDirectory::set_key` error
#[derive(Debug)] #[derive(Debug)]

View File

@ -284,7 +284,7 @@ mod test {
use std::fs; use std::fs;
use std::io::Write; use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
use dir::VaultKey; use super::VaultKey;
use super::{VAULT_FILE_NAME, check_vault_name, make_vault_dir_path, create_vault_file, read_vault_file, VaultDiskDirectory}; use super::{VAULT_FILE_NAME, check_vault_name, make_vault_dir_path, create_vault_file, read_vault_file, VaultDiskDirectory};
use self::tempdir::TempDir; use self::tempdir::TempDir;

View File

@ -1,96 +0,0 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Common tools paths.
use std::env;
use std::path::PathBuf;
fn home() -> PathBuf {
env::home_dir().expect("Failed to get home dir")
}
/// Geth path
pub fn geth(testnet: bool) -> PathBuf {
let mut base = geth_base();
if testnet {
base.push("testnet");
}
base.push("keystore");
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")]
fn parity_base() -> PathBuf {
let mut home = home();
home.push("Library");
home.push("Application Support");
home.push("io.parity.ethereum");
home.push("keys");
home
}
#[cfg(windows)]
fn parity_base() -> PathBuf {
let mut home = home();
home.push("AppData");
home.push("Roaming");
home.push("Parity");
home.push("Ethereum");
home.push("keys");
home
}
#[cfg(not(any(target_os = "macos", windows)))]
fn parity_base() -> PathBuf {
let mut home = home();
home.push(".local");
home.push("share");
home.push("io.parity.ethereum");
home.push("keys");
home
}
#[cfg(target_os = "macos")]
fn geth_base() -> PathBuf {
let mut home = home();
home.push("Library");
home.push("Ethereum");
home
}
#[cfg(windows)]
fn geth_base() -> PathBuf {
let mut home = home();
home.push("AppData");
home.push("Roaming");
home.push("Ethereum");
home
}
#[cfg(not(any(target_os = "macos", windows)))]
fn geth_base() -> PathBuf {
let mut home = home();
home.push(".ethereum");
home
}

View File

@ -23,7 +23,7 @@ use std::time::{Instant, Duration};
use crypto::KEY_ITERATIONS; use crypto::KEY_ITERATIONS;
use random::Random; use random::Random;
use ethkey::{self, Signature, Address, Message, Secret, Public, KeyPair, ExtendedKeyPair}; use ethkey::{self, Signature, Address, Message, Secret, Public, KeyPair, ExtendedKeyPair};
use dir::{KeyDirectory, VaultKeyDirectory, VaultKey, SetKeyError}; use accounts_dir::{KeyDirectory, VaultKeyDirectory, VaultKey, SetKeyError};
use account::SafeAccount; use account::SafeAccount;
use presale::PresaleWallet; use presale::PresaleWallet;
use json::{self, Uuid, OpaqueKeyFile}; use json::{self, Uuid, OpaqueKeyFile};
@ -684,7 +684,7 @@ impl SimpleSecretStore for EthMultiStore {
mod tests { mod tests {
extern crate tempdir; extern crate tempdir;
use dir::{KeyDirectory, MemoryDirectory, RootDiskDirectory}; use accounts_dir::{KeyDirectory, MemoryDirectory, RootDiskDirectory};
use ethkey::{Random, Generator, KeyPair}; use ethkey::{Random, Generator, KeyPair};
use secret_store::{SimpleSecretStore, SecretStore, SecretVaultRef, StoreAccountRef, Derivation}; use secret_store::{SimpleSecretStore, SecretStore, SecretVaultRef, StoreAccountRef, Derivation};
use super::{EthStore, EthMultiStore}; use super::{EthStore, EthMultiStore};

View File

@ -19,7 +19,8 @@ use std::path::Path;
use std::fs; use std::fs;
use ethkey::Address; use ethkey::Address;
use dir::{paths, KeyDirectory, RootDiskDirectory, DiskKeyFileManager, KeyFileManager}; use accounts_dir::{KeyDirectory, RootDiskDirectory, DiskKeyFileManager, KeyFileManager};
use dir;
use Error; use Error;
/// Import an account from a file. /// Import an account from a file.
@ -54,7 +55,7 @@ pub fn import_accounts(src: &KeyDirectory, dst: &KeyDirectory) -> Result<Vec<Add
/// Provide a `HashSet` of all accounts available for import from the Geth keystore. /// Provide a `HashSet` of all accounts available for import from the Geth keystore.
pub fn read_geth_accounts(testnet: bool) -> Vec<Address> { pub fn read_geth_accounts(testnet: bool) -> Vec<Address> {
RootDiskDirectory::at(paths::geth(testnet)) RootDiskDirectory::at(dir::geth(testnet))
.load() .load()
.map(|d| d.into_iter().map(|a| a.address).collect()) .map(|d| d.into_iter().map(|a| a.address).collect())
.unwrap_or_else(|_| Vec::new()) .unwrap_or_else(|_| Vec::new())
@ -62,7 +63,7 @@ pub fn read_geth_accounts(testnet: bool) -> Vec<Address> {
/// Import specific `desired` accounts from the Geth keystore into `dst`. /// Import specific `desired` accounts from the Geth keystore into `dst`.
pub fn import_geth_accounts(dst: &KeyDirectory, desired: HashSet<Address>, testnet: bool) -> Result<Vec<Address>, Error> { pub fn import_geth_accounts(dst: &KeyDirectory, desired: HashSet<Address>, testnet: bool) -> Result<Vec<Address>, Error> {
let src = RootDiskDirectory::at(paths::geth(testnet)); let src = RootDiskDirectory::at(dir::geth(testnet));
let accounts = src.load()?; let accounts = src.load()?;
let existing_accounts = dst.load()?.into_iter().map(|a| a.address).collect::<HashSet<_>>(); let existing_accounts = dst.load()?.into_iter().map(|a| a.address).collect::<HashSet<_>>();

View File

@ -19,6 +19,7 @@
#![warn(missing_docs)] #![warn(missing_docs)]
extern crate crypto as rcrypto; extern crate crypto as rcrypto;
extern crate dir;
extern crate itertools; extern crate itertools;
extern crate libc; extern crate libc;
extern crate parking_lot; extern crate parking_lot;
@ -41,7 +42,7 @@ extern crate log;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
pub mod dir; pub mod accounts_dir;
pub mod ethkey; pub mod ethkey;
mod account; mod account;

View File

@ -21,7 +21,7 @@ mod util;
use ethstore::{EthStore, SimpleSecretStore, SecretVaultRef, StoreAccountRef}; use ethstore::{EthStore, SimpleSecretStore, SecretVaultRef, StoreAccountRef};
use ethstore::ethkey::{Random, Generator, Secret, KeyPair, verify_address}; use ethstore::ethkey::{Random, Generator, Secret, KeyPair, verify_address};
use ethstore::dir::RootDiskDirectory; use ethstore::accounts_dir::RootDiskDirectory;
use util::TransientDir; use util::TransientDir;
#[test] #[test]

View File

@ -17,7 +17,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use std::{env, fs}; use std::{env, fs};
use rand::{Rng, OsRng}; use rand::{Rng, OsRng};
use ethstore::dir::{KeyDirectory, RootDiskDirectory}; use ethstore::accounts_dir::{KeyDirectory, RootDiskDirectory};
use ethstore::{Error, SafeAccount}; use ethstore::{Error, SafeAccount};
pub fn random_dir() -> PathBuf { pub fn random_dir() -> PathBuf {

View File

@ -16,7 +16,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use ethcore::ethstore::{EthStore, SecretStore, import_account, import_accounts, read_geth_accounts}; use ethcore::ethstore::{EthStore, SecretStore, import_account, import_accounts, read_geth_accounts};
use ethcore::ethstore::dir::RootDiskDirectory; use ethcore::ethstore::accounts_dir::RootDiskDirectory;
use ethcore::ethstore::SecretVaultRef; use ethcore::ethstore::SecretVaultRef;
use ethcore::account_provider::{AccountProvider, AccountProviderSettings}; use ethcore::account_provider::{AccountProvider, AccountProviderSettings};
use helpers::{password_prompt, password_from_file}; use helpers::{password_prompt, password_from_file};

View File

@ -154,7 +154,7 @@ macro_rules! usage {
use std::io::{Read, Write}; use std::io::{Read, Write};
use parity_version::version; use parity_version::version;
use clap::{Arg, App, SubCommand, AppSettings, ArgMatches as ClapArgMatches, Error as ClapError, ErrorKind as ClapErrorKind}; use clap::{Arg, App, SubCommand, AppSettings, ArgMatches as ClapArgMatches, Error as ClapError, ErrorKind as ClapErrorKind};
use helpers::replace_home; use dir::helpers::replace_home;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::collections::HashMap; use std::collections::HashMap;

View File

@ -39,8 +39,9 @@ use rpc::{IpcConfiguration, HttpConfiguration, WsConfiguration, UiConfiguration}
use rpc_apis::ApiSet; use rpc_apis::ApiSet;
use parity_rpc::NetworkSettings; use parity_rpc::NetworkSettings;
use cache::CacheConfig; use cache::CacheConfig;
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home, replace_home_and_local, use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, geth_ipc_path, parity_ipc_path,
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy}; to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy};
use dir::helpers::{replace_home, replace_home_and_local};
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras, SpecType}; use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras, SpecType};
use ethcore_logger::Config as LogConfig; use ethcore_logger::Config as LogConfig;
use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path}; use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path};
@ -1851,7 +1852,7 @@ mod tests {
let base_path = ::dir::default_data_path(); let base_path = ::dir::default_data_path();
let local_path = ::dir::default_local_path(); let local_path = ::dir::default_local_path();
assert_eq!(std.directories().cache, ::helpers::replace_home_and_local(&base_path, &local_path, ::dir::CACHE_PATH)); assert_eq!(std.directories().cache, dir::helpers::replace_home_and_local(&base_path, &local_path, ::dir::CACHE_PATH));
assert_eq!(base.directories().cache, "/test/cache"); assert_eq!(base.directories().cache, "/test/cache");
} }
} }

View File

@ -18,13 +18,13 @@ use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
use dir::default_data_path; use dir::default_data_path;
use dir::helpers::replace_home;
use ethcore::client::{Client, BlockChainClient, BlockId}; use ethcore::client::{Client, BlockChainClient, BlockId};
use ethcore::transaction::{Transaction, Action}; use ethcore::transaction::{Transaction, Action};
use ethsync::LightSync; use ethsync::LightSync;
use futures::{future, IntoFuture, Future}; use futures::{future, IntoFuture, Future};
use hash_fetch::fetch::Client as FetchClient; use hash_fetch::fetch::Client as FetchClient;
use hash_fetch::urlhint::ContractClient; use hash_fetch::urlhint::ContractClient;
use helpers::replace_home;
use light::client::LightChainClient; use light::client::LightChainClient;
use light::on_demand::{self, OnDemand}; use light::on_demand::{self, OnDemand};
use node_health::{SyncStatus, NodeHealth}; use node_health::{SyncStatus, NodeHealth};

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::{io, env}; use std::io;
use std::io::{Write, BufReader, BufRead}; use std::io::{Write, BufReader, BufRead};
use std::time::Duration; use std::time::Duration;
use std::fs::File; use std::fs::File;
@ -27,6 +27,7 @@ use ethcore::client::{Mode, BlockId, VMType, DatabaseCompactionProfile, ClientCo
use ethcore::miner::{PendingSet, GasLimit, PrioritizationStrategy}; use ethcore::miner::{PendingSet, GasLimit, PrioritizationStrategy};
use cache::CacheConfig; use cache::CacheConfig;
use dir::DatabaseDirectories; use dir::DatabaseDirectories;
use dir::helpers::replace_home;
use upgrade::{upgrade, upgrade_data_paths}; use upgrade::{upgrade, upgrade_data_paths};
use migration::migrate; use migration::migrate;
use ethsync::{validate_node_url, self}; use ethsync::{validate_node_url, self};
@ -135,19 +136,6 @@ pub fn to_price(s: &str) -> Result<f32, String> {
s.parse::<f32>().map_err(|_| format!("Invalid transaciton price 's' given. Must be a decimal number.")) s.parse::<f32>().map_err(|_| format!("Invalid transaciton price 's' given. Must be a decimal number."))
} }
/// 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`
let r = arg.replace("$HOME", env::home_dir().unwrap().to_str().unwrap());
let r = r.replace("$BASE", base);
r.replace("/", &::std::path::MAIN_SEPARATOR.to_string())
}
pub fn replace_home_and_local(base: &str, local: &str, arg: &str) -> String {
let r = replace_home(base, arg);
r.replace("$LOCAL", local)
}
/// Flush output buffer. /// Flush output buffer.
pub fn flush_stdout() { pub fn flush_stdout() {
io::stdout().flush().expect("stdout is flushable; qed"); io::stdout().flush().expect("stdout is flushable; qed");

View File

@ -24,6 +24,7 @@ extern crate ctrlc;
extern crate docopt; extern crate docopt;
#[macro_use] #[macro_use]
extern crate clap; extern crate clap;
extern crate dir;
extern crate env_logger; extern crate env_logger;
extern crate fdlimit; extern crate fdlimit;
extern crate futures; extern crate futures;
@ -102,7 +103,6 @@ mod configuration;
mod dapps; mod dapps;
mod ipfs; mod ipfs;
mod deprecated; mod deprecated;
mod dir;
mod helpers; mod helpers;
mod informant; mod informant;
mod light_helpers; mod light_helpers;

View File

@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use ethcore::ethstore::{PresaleWallet, EthStore}; use ethcore::ethstore::{PresaleWallet, EthStore};
use ethcore::ethstore::dir::RootDiskDirectory; use ethcore::ethstore::accounts_dir::RootDiskDirectory;
use ethcore::account_provider::{AccountProvider, AccountProviderSettings}; use ethcore::account_provider::{AccountProvider, AccountProviderSettings};
use helpers::{password_prompt, password_from_file}; use helpers::{password_prompt, password_from_file};
use params::SpecType; use params::SpecType;

View File

@ -21,7 +21,8 @@ use std::collections::HashSet;
use dapps; use dapps;
use dir::default_data_path; use dir::default_data_path;
use helpers::{parity_ipc_path, replace_home}; use dir::helpers::replace_home;
use helpers::parity_ipc_path;
use jsonrpc_core::MetaIoHandler; use jsonrpc_core::MetaIoHandler;
use parity_reactor::TokioRemote; use parity_reactor::TokioRemote;
use parity_rpc::informant::{RpcStats, Middleware}; use parity_rpc::informant::{RpcStats, Middleware};

View File

@ -893,7 +893,7 @@ fn print_running_environment(spec_name: &String, dirs: &Directories, db_dirs: &D
fn prepare_account_provider(spec: &SpecType, dirs: &Directories, data_dir: &str, cfg: AccountsConfig, passwords: &[String]) -> Result<AccountProvider, String> { fn prepare_account_provider(spec: &SpecType, dirs: &Directories, data_dir: &str, cfg: AccountsConfig, passwords: &[String]) -> Result<AccountProvider, String> {
use ethcore::ethstore::EthStore; use ethcore::ethstore::EthStore;
use ethcore::ethstore::dir::RootDiskDirectory; use ethcore::ethstore::accounts_dir::RootDiskDirectory;
let path = dirs.keys_path(data_dir); let path = dirs.keys_path(data_dir);
upgrade_key_location(&dirs.legacy_keys_path(cfg.testnet), &path); upgrade_key_location(&dirs.legacy_keys_path(cfg.testnet), &path);

View File

@ -17,10 +17,10 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::sync::Arc; use std::sync::Arc;
use dir::default_data_path; use dir::default_data_path;
use dir::helpers::replace_home;
use ethcore::account_provider::AccountProvider; use ethcore::account_provider::AccountProvider;
use ethcore::client::Client; use ethcore::client::Client;
use ethkey::{Secret, Public}; use ethkey::{Secret, Public};
use helpers::replace_home;
use util::Address; use util::Address;
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]

View File

@ -24,7 +24,7 @@ use std::io;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::{PathBuf, Path}; use std::path::{PathBuf, Path};
use dir::{DatabaseDirectories, default_data_path}; use dir::{DatabaseDirectories, default_data_path};
use helpers::replace_home; use dir::helpers::replace_home;
use journaldb::Algorithm; use journaldb::Algorithm;
#[derive(Debug)] #[derive(Debug)]

View File

@ -18,7 +18,7 @@ use std::sync::Arc;
use ethcore::account_provider::{AccountProvider, AccountProviderSettings}; use ethcore::account_provider::{AccountProvider, AccountProviderSettings};
use ethstore::EthStore; use ethstore::EthStore;
use ethstore::dir::RootDiskDirectory; use ethstore::accounts_dir::RootDiskDirectory;
use devtools::RandomTempPath; use devtools::RandomTempPath;
use jsonrpc_core::IoHandler; use jsonrpc_core::IoHandler;

9
util/dir/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "dir"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
ethcore-bigint = { path = "../bigint" }
journaldb = { path = "../journaldb" }
app_dirs = "1.1.1"

31
util/dir/src/helpers.rs Normal file
View File

@ -0,0 +1,31 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::env;
/// 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`
let r = arg.replace("$HOME", env::home_dir().unwrap().to_str().unwrap());
let r = r.replace("$BASE", base);
r.replace("/", &::std::path::MAIN_SEPARATOR.to_string())
}
/// Replaces `$HOME` str with home directory path and `$LOCAL` with local path.
pub fn replace_home_and_local(base: &str, local: &str, arg: &str) -> String {
let r = replace_home(base, arg);
r.replace("$LOCAL", local)
}

View File

@ -14,7 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::fs; extern crate app_dirs;
extern crate ethcore_bigint as bigint;
extern crate journaldb;
pub mod helpers;
use std::{env, fs};
use std::path::{PathBuf, Path}; use std::path::{PathBuf, Path};
use bigint::hash::{H64, H256}; use bigint::hash::{H64, H256};
use journaldb::Algorithm; use journaldb::Algorithm;
@ -234,6 +239,81 @@ pub fn default_hypervisor_path() -> String {
get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity-hypervisor".to_owned()) get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity-hypervisor".to_owned())
} }
fn home() -> PathBuf {
env::home_dir().expect("Failed to get home dir")
}
/// Geth path
pub fn geth(testnet: bool) -> PathBuf {
let mut base = geth_base();
if testnet {
base.push("testnet");
}
base.push("keystore");
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")]
fn parity_base() -> PathBuf {
let mut home = home();
home.push("Library");
home.push("Application Support");
home.push("io.parity.ethereum");
home.push("keys");
home
}
#[cfg(windows)]
fn parity_base() -> PathBuf {
let mut home = home();
home.push("AppData");
home.push("Roaming");
home.push("Parity");
home.push("Ethereum");
home.push("keys");
home
}
#[cfg(not(any(target_os = "macos", windows)))]
fn parity_base() -> PathBuf {
let mut home = home();
home.push(".local");
home.push("share");
home.push("io.parity.ethereum");
home.push("keys");
home
}
#[cfg(target_os = "macos")]
fn geth_base() -> PathBuf {
let mut home = home();
home.push("Library");
home.push("Ethereum");
home
}
#[cfg(windows)]
fn geth_base() -> PathBuf {
let mut home = home();
home.push("AppData");
home.push("Roaming");
home.push("Ethereum");
home
}
#[cfg(not(any(target_os = "macos", windows)))]
fn geth_base() -> PathBuf {
let mut home = home();
home.push(".ethereum");
home
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::Directories; use super::Directories;