Merge pull request #912 from ethcore/keys-path-fix-create

create provided custom dir for keys if none
This commit is contained in:
Nikolay Volf 2016-04-10 17:01:51 +04:00
commit 032d29ec86

View File

@ -121,22 +121,7 @@ impl AccountProvider for AccountService {
} }
} }
impl Default for AccountService {
fn default() -> Self {
AccountService::new()
}
}
impl AccountService { impl AccountService {
/// New account service with the keys store in default location
pub fn new() -> Self {
let secret_store = RwLock::new(SecretStore::new());
secret_store.write().unwrap().try_import_existing();
AccountService {
secret_store: secret_store
}
}
/// New account service with the keys store in specific location /// New account service with the keys store in specific location
pub fn new_in(path: &Path) -> Self { pub fn new_in(path: &Path) -> Self {
let secret_store = RwLock::new(SecretStore::new_in(path)); let secret_store = RwLock::new(SecretStore::new_in(path));
@ -165,25 +150,10 @@ impl AccountService {
} }
} }
impl Default for SecretStore {
fn default() -> Self {
SecretStore::new()
}
}
impl SecretStore { impl SecretStore {
/// new instance of Secret Store in default home directory
pub fn new() -> Self {
let mut path = ::std::env::home_dir().expect("Failed to get home dir");
path.push(".parity");
path.push("keys");
::std::fs::create_dir_all(&path).expect("Should panic since it is critical to be able to access home dir");
Self::new_in(&path)
}
/// new instance of Secret Store in specific directory /// new instance of Secret Store in specific directory
pub fn new_in(path: &Path) -> Self { pub fn new_in(path: &Path) -> Self {
::std::fs::create_dir_all(&path).expect("Cannot access requested key directory - critical");
SecretStore { SecretStore {
directory: KeyDirectory::new(path), directory: KeyDirectory::new(path),
unlocks: RwLock::new(HashMap::new()), unlocks: RwLock::new(HashMap::new()),