use std::path::{Path, PathBuf};
#[derive(Debug, Clone)]
pub struct CacheDir {
root: PathBuf,
}
impl CacheDir {
pub fn discover() -> std::io::Result<Self> {
let root = dirs::cache_dir()
.unwrap_or_else(|| {
PathBuf::from(std::env::var("HOME").unwrap_or_else(|_| ".".into())).join(".cache")
})
.join("caixa");
std::fs::create_dir_all(&root)?;
Ok(Self { root })
}
#[must_use]
pub fn at(path: impl Into<PathBuf>) -> Self {
Self { root: path.into() }
}
#[must_use]
pub fn root(&self) -> &Path {
&self.root
}
#[must_use]
pub fn source_dir(&self, key: &str) -> PathBuf {
self.root.join("sources").join(key)
}
}