summaryrefslogtreecommitdiff
path: root/src/dirs.rs
blob: de7c15672547b1459cfe48cb6989b7315d8f7481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::{env, path::PathBuf};

pub fn store_path() -> Option<PathBuf> {
    cache_dir().map(|c| c.join("syn"))
}

fn cache_dir() -> Option<PathBuf> {
    env::var_os("XDG_CACHE_HOME")
        .map(PathBuf::from)
        .or_else(|| home_dir().map(|h| h.join(".cache")))
}

fn home_dir() -> Option<PathBuf> {
    env::var_os("HOME")
        .and_then(|h| if h.is_empty() { None } else { Some(h) })
        .map(PathBuf::from)
}