From d6138d5986016c72f6caeafce4696f38df48e504 Mon Sep 17 00:00:00 2001 From: mars Date: Wed, 19 Apr 2023 23:46:08 -0400 Subject: [PATCH] Fixed get_*_dir() result handling --- src/config.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 35fe0fb..819f96f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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")