summaryrefslogtreecommitdiff
path: root/src/dirs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dirs.rs')
-rw-r--r--src/dirs.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/dirs.rs b/src/dirs.rs
new file mode 100644
index 0000000..de7c156
--- /dev/null
+++ b/src/dirs.rs
@@ -0,0 +1,17 @@
1use std::{env, path::PathBuf};
2
3pub fn store_path() -> Option<PathBuf> {
4 cache_dir().map(|c| c.join("syn"))
5}
6
7fn cache_dir() -> Option<PathBuf> {
8 env::var_os("XDG_CACHE_HOME")
9 .map(PathBuf::from)
10 .or_else(|| home_dir().map(|h| h.join(".cache")))
11}
12
13fn home_dir() -> Option<PathBuf> {
14 env::var_os("HOME")
15 .and_then(|h| if h.is_empty() { None } else { Some(h) })
16 .map(PathBuf::from)
17}