* Util funtions to get OS-standard config path.

* Build fix.
This commit is contained in:
Gav Wood 2016-07-17 23:00:47 +02:00 committed by GitHub
parent 5ab18d1313
commit 34b7cf2e0a

View File

@ -16,51 +16,65 @@
//! Path utilities //! Path utilities
use std::path::Path; use std::path::Path;
use std::path::PathBuf;
#[cfg(target_os = "macos")]
/// Get the config path for application `name`.
/// `name` should be capitalized, e.g. `"Ethereum"`, `"Parity"`.
pub fn config_path(name: &str) -> PathBuf {
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
home.push("Library");
home.push(name);
home
}
#[cfg(windows)]
/// Get the config path for application `name`.
/// `name` should be capitalized, e.g. `"Ethereum"`, `"Parity"`.
pub fn config_path(name: &str) -> PathBuf {
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
home.push("AppData");
home.push("Roaming");
home.push(name);
home
}
#[cfg(not(any(target_os = "macos", windows)))]
/// Get the config path for application `name`.
/// `name` should be capitalized, e.g. `"Ethereum"`, `"Parity"`.
pub fn config_path(name: &str) -> PathBuf {
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
home.push(format!(".{}", name.to_lowercase()));
home
}
/// Get the specific folder inside a config path.
pub fn config_path_with(name: &str, then: &str) -> PathBuf {
let mut path = config_path(name);
path.push(then);
path
}
/// Default ethereum paths /// Default ethereum paths
pub mod ethereum { pub mod ethereum {
use std::path::PathBuf; use std::path::PathBuf;
#[cfg(target_os = "macos")]
/// Default path for ethereum installation on Mac Os /// Default path for ethereum installation on Mac Os
pub fn default() -> PathBuf { pub fn default() -> PathBuf { super::config_path("Ethereum") }
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 is 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 /// Get the specific folder inside default ethereum installation
pub fn with_default(s: &str) -> PathBuf { pub fn with_default(s: &str) -> PathBuf {
let mut pth = default(); let mut path = default();
pth.push(s); path.push(s);
pth path
} }
/// Get the specific folder inside default ethereum installation configured for testnet /// Get the specific folder inside default ethereum installation configured for testnet
pub fn with_testnet(s: &str) -> PathBuf { pub fn with_testnet(s: &str) -> PathBuf {
let mut pth = default(); let mut path = default();
pth.push("testnet"); path.push("testnet");
pth.push(s); path.push(s);
pth path
} }
} }