mod for paths & ethereum default paths
This commit is contained in:
parent
06aefb54bc
commit
d5d5b0918c
@ -20,6 +20,7 @@ use common::*;
|
||||
use keys::store::SecretStore;
|
||||
use keys::directory::KeyFileContent;
|
||||
use std::path::PathBuf;
|
||||
use path;
|
||||
|
||||
/// Enumerates all geth keys in the directory and returns collection of tuples `(accountId, filename)`
|
||||
pub fn enumerate_geth_keys(path: &Path) -> Result<Vec<(Address, String)>, ImportError> {
|
||||
@ -98,30 +99,7 @@ pub fn import_geth_keys(secret_store: &mut SecretStore, geth_keyfiles_directory:
|
||||
///
|
||||
/// Based on https://github.com/ethereum/go-ethereum/blob/e553215/common/path.go#L75
|
||||
pub fn keystore_dir() -> PathBuf {
|
||||
#[cfg(target_os = "macos")]
|
||||
fn data_dir(mut home: PathBuf) -> PathBuf {
|
||||
home.push("Library");
|
||||
home.push("Ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn data_dir(mut home: PathBuf) -> PathBuf {
|
||||
home.push("AppData");
|
||||
home.push("Roaming");
|
||||
home.push("Ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", windows)))]
|
||||
fn data_dir(mut home: PathBuf) -> PathBuf {
|
||||
home.push(".ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
let mut data_dir = data_dir(::std::env::home_dir().expect("Failed to get home dir"));
|
||||
data_dir.push("keystore");
|
||||
data_dir
|
||||
path::ethereum::with_default("keystore")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -148,6 +148,7 @@ pub mod panics;
|
||||
pub mod keys;
|
||||
pub mod table;
|
||||
pub mod network_settings;
|
||||
pub mod path;
|
||||
|
||||
pub use common::*;
|
||||
pub use misc::*;
|
||||
|
57
util/src/path.rs
Normal file
57
util/src/path.rs
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright 2015, 2016 Ethcore (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/>.
|
||||
|
||||
//! Path utilities
|
||||
|
||||
/// Default ethereum paths
|
||||
pub mod ethereum {
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
/// Default path for ethereum installation on Mac Os
|
||||
pub fn default() -> PathBuf {
|
||||
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
|
||||
home.push("Library");
|
||||
home.push("Ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
/// Default path for ethereum installation on Windows
|
||||
pub fn default() -> PathBuf {
|
||||
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
|
||||
home.push("AppData");
|
||||
home.push("Roaming");
|
||||
home.push("Ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", windows)))]
|
||||
/// Default path for ethereum installation on posix system which and not Mac OS
|
||||
pub fn default() -> PathBuf {
|
||||
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
|
||||
home.push(".ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
/// Get the specific folder inside default ethereum installation
|
||||
pub fn with_default(s: &str) -> PathBuf {
|
||||
let mut pth = default();
|
||||
pth.push(s);
|
||||
pth
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user