30 lines
656 B
Rust
30 lines
656 B
Rust
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug)]
|
|
pub struct FetcherCache {
|
|
base_dir: PathBuf,
|
|
}
|
|
|
|
impl FetcherCache {
|
|
pub fn new() -> Result<Self, std::io::Error> {
|
|
let base_dir = dirs::cache_dir()
|
|
.unwrap_or_else(|| PathBuf::from("/tmp"))
|
|
.join("fix")
|
|
.join("fetchers");
|
|
|
|
fs::create_dir_all(&base_dir)?;
|
|
|
|
Ok(Self { base_dir })
|
|
}
|
|
|
|
fn git_cache_dir(&self) -> PathBuf {
|
|
self.base_dir.join("git")
|
|
}
|
|
|
|
pub fn get_git_bare(&self, url: &str) -> PathBuf {
|
|
let key = crate::nix_utils::sha256_hex(url.as_bytes());
|
|
self.git_cache_dir().join(key)
|
|
}
|
|
}
|