#[cfg(not(target_arch = "wasm32"))]
use std::path::{Path, PathBuf};
#[cfg(not(target_arch = "wasm32"))]
use sha2::{Digest, Sha256};
#[cfg(not(target_arch = "wasm32"))]
use crate::analysis::Fingerprint;
#[cfg(not(target_arch = "wasm32"))]
use crate::util::bytes_to_hex;
#[cfg(not(target_arch = "wasm32"))]
pub struct DriverCache {
cache_dir: PathBuf,
}
#[cfg(not(target_arch = "wasm32"))]
impl DriverCache {
pub fn open(project_root: &Path) -> Self {
let cache_dir = project_root.join(".crepus-cache");
std::fs::create_dir_all(&cache_dir).ok();
Self { cache_dir }
}
pub fn is_up_to_date(&self, fp: &Fingerprint, output: &str) -> bool {
let entry_path = self.entry_path(fp);
match std::fs::read_to_string(&entry_path) {
Ok(stored) => stored == self.output_hash(output),
Err(_) => false,
}
}
pub fn record(&self, fp: &Fingerprint, output: &str) {
let entry_path = self.entry_path(fp);
let _ = std::fs::write(&entry_path, self.output_hash(output));
}
fn entry_path(&self, fp: &Fingerprint) -> PathBuf {
self.cache_dir.join(fp.cache_key())
}
fn output_hash(&self, output: &str) -> String {
let mut h = Sha256::new();
h.update(output.as_bytes());
bytes_to_hex(h.finalize().as_ref())
}
}