move helper functions to platform module

This commit is contained in:
Nicolas Ochem 2017-12-25 22:25:19 -08:00
parent 2e12a2db50
commit 268e8f5a64

View File

@ -245,7 +245,7 @@ fn home() -> PathBuf {
/// Geth path /// Geth path
pub fn geth(testnet: bool) -> PathBuf { pub fn geth(testnet: bool) -> PathBuf {
let mut base = geth_base(); let mut base = platform::geth_base();
if testnet { if testnet {
base.push("testnet"); base.push("testnet");
} }
@ -255,65 +255,69 @@ pub fn geth(testnet: bool) -> PathBuf {
/// Parity path for specific chain /// Parity path for specific chain
pub fn parity(chain: &str) -> PathBuf { pub fn parity(chain: &str) -> PathBuf {
let mut base = parity_base(); let mut base = platform::parity_base();
base.push(chain); base.push(chain);
base base
} }
#[cfg(target_os = "macos")] mod platform {
fn parity_base() -> PathBuf { use std::path::PathBuf;
let mut home = home(); #[cfg(target_os = "macos")]
pub fn parity_base() -> PathBuf {
let mut home = super::home();
home.push("Library"); home.push("Library");
home.push("Application Support"); home.push("Application Support");
home.push("io.parity.ethereum"); home.push("io.parity.ethereum");
home.push("keys"); home.push("keys");
home home
} }
#[cfg(windows)] #[cfg(windows)]
fn parity_base() -> PathBuf { pub fn parity_base() -> PathBuf {
let mut home = home(); let mut home = super::home();
home.push("AppData"); home.push("AppData");
home.push("Roaming"); home.push("Roaming");
home.push("Parity"); home.push("Parity");
home.push("Ethereum"); home.push("Ethereum");
home.push("keys"); home.push("keys");
home home
} }
#[cfg(not(any(target_os = "macos", windows)))] #[cfg(not(any(target_os = "macos", windows)))]
fn parity_base() -> PathBuf { pub fn parity_base() -> PathBuf {
let mut home = home(); let mut home = super::home();
home.push(".local"); home.push(".local");
home.push("share"); home.push("share");
home.push("io.parity.ethereum"); home.push("io.parity.ethereum");
home.push("keys"); home.push("keys");
home home
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn geth_base() -> PathBuf { pub fn geth_base() -> PathBuf {
let mut home = home(); let mut home = super::home();
home.push("Library"); home.push("Library");
home.push("Ethereum"); home.push("Ethereum");
home home
} }
#[cfg(windows)] #[cfg(windows)]
fn geth_base() -> PathBuf { pub fn geth_base() -> PathBuf {
let mut home = home(); let mut home = super::home();
home.push("AppData"); home.push("AppData");
home.push("Roaming"); home.push("Roaming");
home.push("Ethereum"); home.push("Ethereum");
home home
} }
#[cfg(not(any(target_os = "macos", windows)))] #[cfg(not(any(target_os = "macos", windows)))]
fn geth_base() -> PathBuf { pub fn geth_base() -> PathBuf {
let mut home = home(); let mut home = super::home();
home.push(".ethereum"); home.push(".ethereum");
home home
}
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::Directories; use super::Directories;