clean up
This commit is contained in:
29
fix/src/fetcher/cache.rs
Normal file
29
fix/src/fetcher/cache.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user