diff --git a/src/dirs.rs b/src/dirs.rs index 7895c523..29e79b2e 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -18,7 +18,8 @@ impl BatProjectDirs { fn new() -> Option { #[cfg(target_os = "macos")] let cache_dir_op = env::var_os("XDG_CACHE_HOME") - .and_then(is_absolute_path) + .map(PathBuf::from) + .filter(|p| p.is_absolute()) .or_else(|| dirs_rs::home_dir().map(|d| d.join(".cache"))); #[cfg(not(target_os = "macos"))] @@ -31,7 +32,8 @@ impl BatProjectDirs { #[cfg(target_os = "macos")] let config_dir_op = env::var_os("XDG_CONFIG_HOME") - .and_then(is_absolute_path) + .map(PathBuf::from) + .filter(|p| p.is_absolute()) .or_else(|| dirs_rs::home_dir().map(|d| d.join(".config"))); #[cfg(not(target_os = "macos"))] @@ -57,17 +59,6 @@ impl BatProjectDirs { } } -// Returns path if it is an absolute path -#[cfg(target_os = "macos")] -fn is_absolute_path(path: OsString) -> Option { - let path = PathBuf::from(path); - if path.is_absolute() { - Some(path) - } else { - None - } -} - lazy_static! { pub static ref PROJECT_DIRS: BatProjectDirs = BatProjectDirs::new().expect("Could not get home directory");