Fixed get_*_dir() result handling

This commit is contained in:
mars 2023-04-19 23:46:08 -04:00
parent 487b8e4580
commit d6138d5986
1 changed files with 8 additions and 10 deletions

View File

@ -47,13 +47,12 @@ impl Default for Config {
/// Gets the configuration directory. Panics if unavailable.
pub fn get_config_dir() -> PathBuf {
std::env::var_os("XDG_CONFIG_HOME")
.map(PathBuf::try_from)
.expect("$XDG_CONFIG_HOME is unset.")
.unwrap_or_else(|_| {
.map(|p| PathBuf::try_from(p).expect("$XDG_CONFIG_HOME is not a valid path."))
.unwrap_or_else(|| {
std::env::var_os("HOME")
.map(PathBuf::try_from)
.expect("User has no $HOME.")
.unwrap()
.expect("$HOME is not a valid path.")
.expect("User has no $HOME or $XDG_CONFIG_HOME.")
.join(".config")
})
.join("breed")
@ -61,13 +60,12 @@ pub fn get_config_dir() -> PathBuf {
pub fn get_data_dir() -> PathBuf {
std::env::var_os("XDG_DATA_HOME")
.map(PathBuf::try_from)
.expect("$XDG_DATA_HOME is unset.")
.unwrap_or_else(|_| {
.map(|p| PathBuf::try_from(p).expect("$XDG_DATA_HOME is not a valid path."))
.unwrap_or_else(|| {
std::env::var_os("HOME")
.map(PathBuf::try_from)
.expect("User has no $HOME.")
.unwrap()
.expect("$HOME is not a valid path.")
.expect("User has no $HOME or $XDG_DATA_HOME.")
.join(".local/share")
})
.join("breed")