forked from mars/breed
Fixed get_*_dir() result handling
This commit is contained in:
parent
487b8e4580
commit
d6138d5986
|
@ -47,13 +47,12 @@ impl Default for Config {
|
||||||
/// Gets the configuration directory. Panics if unavailable.
|
/// Gets the configuration directory. Panics if unavailable.
|
||||||
pub fn get_config_dir() -> PathBuf {
|
pub fn get_config_dir() -> PathBuf {
|
||||||
std::env::var_os("XDG_CONFIG_HOME")
|
std::env::var_os("XDG_CONFIG_HOME")
|
||||||
.map(PathBuf::try_from)
|
.map(|p| PathBuf::try_from(p).expect("$XDG_CONFIG_HOME is not a valid path."))
|
||||||
.expect("$XDG_CONFIG_HOME is unset.")
|
.unwrap_or_else(|| {
|
||||||
.unwrap_or_else(|_| {
|
|
||||||
std::env::var_os("HOME")
|
std::env::var_os("HOME")
|
||||||
.map(PathBuf::try_from)
|
.map(PathBuf::try_from)
|
||||||
.expect("User has no $HOME.")
|
.expect("$HOME is not a valid path.")
|
||||||
.unwrap()
|
.expect("User has no $HOME or $XDG_CONFIG_HOME.")
|
||||||
.join(".config")
|
.join(".config")
|
||||||
})
|
})
|
||||||
.join("breed")
|
.join("breed")
|
||||||
|
@ -61,13 +60,12 @@ pub fn get_config_dir() -> PathBuf {
|
||||||
|
|
||||||
pub fn get_data_dir() -> PathBuf {
|
pub fn get_data_dir() -> PathBuf {
|
||||||
std::env::var_os("XDG_DATA_HOME")
|
std::env::var_os("XDG_DATA_HOME")
|
||||||
.map(PathBuf::try_from)
|
.map(|p| PathBuf::try_from(p).expect("$XDG_DATA_HOME is not a valid path."))
|
||||||
.expect("$XDG_DATA_HOME is unset.")
|
.unwrap_or_else(|| {
|
||||||
.unwrap_or_else(|_| {
|
|
||||||
std::env::var_os("HOME")
|
std::env::var_os("HOME")
|
||||||
.map(PathBuf::try_from)
|
.map(PathBuf::try_from)
|
||||||
.expect("User has no $HOME.")
|
.expect("$HOME is not a valid path.")
|
||||||
.unwrap()
|
.expect("User has no $HOME or $XDG_DATA_HOME.")
|
||||||
.join(".local/share")
|
.join(".local/share")
|
||||||
})
|
})
|
||||||
.join("breed")
|
.join("breed")
|
||||||
|
|
Reference in New Issue