Create dir on desktop only

This commit is contained in:
Aditya Kulkarni 2020-05-19 10:05:32 -07:00
parent 7ce977bb82
commit 4c8442fa38

View File

@ -162,9 +162,11 @@ impl LightClientConfig {
}; };
} }
// Create directory if it doesn't exist // Create directory if it doesn't exist on non-mobile platforms
#[cfg(all(not(target_os="ios"), not(target_os="android")))]
{
match std::fs::create_dir_all(zcash_data_location.clone()) { match std::fs::create_dir_all(zcash_data_location.clone()) {
Ok(_) => zcash_data_location.into_boxed_path(), Ok(_) => {},
Err(e) => { Err(e) => {
eprintln!("Couldn't create zcash directory!\n{}", e); eprintln!("Couldn't create zcash directory!\n{}", e);
panic!("Couldn't create zcash directory!"); panic!("Couldn't create zcash directory!");
@ -172,6 +174,9 @@ impl LightClientConfig {
} }
} }
zcash_data_location.into_boxed_path()
}
pub fn get_wallet_path(&self) -> Box<Path> { pub fn get_wallet_path(&self) -> Box<Path> {
let mut wallet_location = self.get_zcash_data_path().into_path_buf(); let mut wallet_location = self.get_zcash_data_path().into_path_buf();
wallet_location.push(WALLET_NAME); wallet_location.push(WALLET_NAME);
@ -322,10 +327,13 @@ impl LightClient {
/// Create a brand new wallet with a new seed phrase. Will fail if a wallet file /// Create a brand new wallet with a new seed phrase. Will fail if a wallet file
/// already exists on disk /// already exists on disk
pub fn new(config: &LightClientConfig, latest_block: u64) -> io::Result<Self> { pub fn new(config: &LightClientConfig, latest_block: u64) -> io::Result<Self> {
#[cfg(all(not(target_os="ios"), not(target_os="android")))]
{
if config.wallet_exists() { if config.wallet_exists() {
return Err(Error::new(ErrorKind::AlreadyExists, return Err(Error::new(ErrorKind::AlreadyExists,
"Cannot create a new wallet from seed, because a wallet already exists")); "Cannot create a new wallet from seed, because a wallet already exists"));
} }
}
let mut l = LightClient { let mut l = LightClient {
wallet : Arc::new(RwLock::new(LightWallet::new(None, config, latest_block)?)), wallet : Arc::new(RwLock::new(LightWallet::new(None, config, latest_block)?)),
@ -349,10 +357,13 @@ impl LightClient {
} }
pub fn new_from_phrase(seed_phrase: String, config: &LightClientConfig, birthday: u64, overwrite: bool) -> io::Result<Self> { pub fn new_from_phrase(seed_phrase: String, config: &LightClientConfig, birthday: u64, overwrite: bool) -> io::Result<Self> {
#[cfg(all(not(target_os="ios"), not(target_os="android")))]
{
if !overwrite && config.wallet_exists() { if !overwrite && config.wallet_exists() {
return Err(Error::new(ErrorKind::AlreadyExists, return Err(Error::new(ErrorKind::AlreadyExists,
"Cannot create a new wallet from seed, because a wallet already exists")); "Cannot create a new wallet from seed, because a wallet already exists"));
} }
}
let mut l = LightClient { let mut l = LightClient {
wallet : Arc::new(RwLock::new(LightWallet::new(Some(seed_phrase), config, birthday)?)), wallet : Arc::new(RwLock::new(LightWallet::new(Some(seed_phrase), config, birthday)?)),