Skip to main content

gqls/
paths.rs

1//! Shared on-disk locations. gqls keeps everything cacheable under one base
2//! dir (`$XDG_CACHE_HOME/gqls`, else `~/.cache/gqls`) — embedding vectors, the
3//! introspection response cache, and the background-warm lockfiles.
4
5use std::path::PathBuf;
6
7/// Base cache directory, or `None` if neither `XDG_CACHE_HOME` nor `HOME` is set.
8pub fn cache_dir() -> Option<PathBuf> {
9    let base = std::env::var_os("XDG_CACHE_HOME")
10        .map(PathBuf::from)
11        .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".cache")))?;
12    Some(base.join("gqls"))
13}
14
15/// Directory for ephemeral files (the background-warm single-flight lockfiles).
16/// The system temp dir so the OS reaps them — they never litter the cache. It's
17/// per-user on macOS (`$TMPDIR`) and `/tmp` on Linux, and stable within a login,
18/// so concurrent gqls processes still see the same lock.
19pub fn temp_dir() -> PathBuf {
20    std::env::temp_dir().join("gqls")
21}