diff --git a/util/dir/src/lib.rs b/util/dir/src/lib.rs index e6d3e33ec..82678f982 100644 --- a/util/dir/src/lib.rs +++ b/util/dir/src/lib.rs @@ -245,7 +245,7 @@ fn home() -> PathBuf { /// Geth path pub fn geth(testnet: bool) -> PathBuf { - let mut base = geth_base(); + let mut base = platform::geth_base(); if testnet { base.push("testnet"); } @@ -255,65 +255,69 @@ pub fn geth(testnet: bool) -> PathBuf { /// Parity path for specific chain pub fn parity(chain: &str) -> PathBuf { - let mut base = parity_base(); + let mut base = platform::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 +mod platform { + use std::path::PathBuf; + #[cfg(target_os = "macos")] + pub fn parity_base() -> PathBuf { + let mut home = super::home(); + home.push("Library"); + home.push("Application Support"); + home.push("io.parity.ethereum"); + home.push("keys"); + home + } + + #[cfg(windows)] + pub fn parity_base() -> PathBuf { + let mut home = super::home(); + home.push("AppData"); + home.push("Roaming"); + home.push("Parity"); + home.push("Ethereum"); + home.push("keys"); + home + } + + #[cfg(not(any(target_os = "macos", windows)))] + pub fn parity_base() -> PathBuf { + let mut home = super::home(); + home.push(".local"); + home.push("share"); + home.push("io.parity.ethereum"); + home.push("keys"); + home + } + + #[cfg(target_os = "macos")] + pub fn geth_base() -> PathBuf { + let mut home = super::home(); + home.push("Library"); + home.push("Ethereum"); + home + } + + #[cfg(windows)] + pub fn geth_base() -> PathBuf { + let mut home = super::home(); + home.push("AppData"); + home.push("Roaming"); + home.push("Ethereum"); + home + } + + #[cfg(not(any(target_os = "macos", windows)))] + pub fn geth_base() -> PathBuf { + let mut home = super::home(); + home.push(".ethereum"); + 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)] mod tests { use super::Directories;