* 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
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
pub mod ethereum {
use std::path::PathBuf;
#[cfg(target_os = "macos")]
/// Default path for ethereum installation on Mac Os
pub fn default() -> PathBuf {
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
}
pub fn default() -> PathBuf { super::config_path("Ethereum") }
/// Get the specific folder inside default ethereum installation
pub fn with_default(s: &str) -> PathBuf {
let mut pth = default();
pth.push(s);
pth
let mut path = default();
path.push(s);
path
}
/// Get the specific folder inside default ethereum installation configured for testnet
pub fn with_testnet(s: &str) -> PathBuf {
let mut pth = default();
pth.push("testnet");
pth.push(s);
pth
let mut path = default();
path.push("testnet");
path.push(s);
path
}
}