use super::*;
pub(super) fn persist_workers_default() -> usize {
if let Ok(v) = std::env::var("ZCCACHE_STORE_WORKERS") {
if let Ok(n) = v.parse::<usize>() {
if n >= 1 {
return n.min(1024);
}
}
}
8
}
pub(super) fn hash_file_via_cache(state: &SharedState, path: &Path) -> Option<ContentHash> {
if let Ok(hash) = state.cache_system.metadata().lookup(path) {
return Some(hash);
}
crate::hash::hash_file(path).ok()
}
pub(super) fn hash_file(
cache_system: &CacheSystem,
path: &Path,
clock: Clock,
) -> Result<ContentHash, String> {
debug_assert!(
!path.to_string_lossy().starts_with(r"\\?\"),
"path must not have \\\\?\\ prefix: {}",
path.display()
);
cache_system
.lookup_since(&NormalizedPath::new(path), clock)
.map(|r| r.hash)
.map_err(|e| format!("{}: {e}", path.display()))
}
pub(super) fn context_files_fresh(
state: &SharedState,
context_key: &ContextKey,
source_path: &Path,
since: Clock,
) -> bool {
let journal = state.cache_system.journal();
if journal.changed_since(&source_path.into(), since) {
return false;
}
if let Some(includes) = state.dep_graph.load().get_includes(context_key) {
for header in &includes {
if journal.changed_since(header, since) {
return false;
}
}
}
if let Some(externs) = state.dep_graph.load().get_rustc_externs(context_key) {
for (_, path) in &externs {
if journal.changed_since(path, since) {
return false;
}
}
}
true
}
pub(super) fn lookup_artifact_with_disk_fallback<'a>(
state: &'a SharedState,
key_hex: &str,
) -> Option<dashmap::mapref::one::RefMut<'a, String, CachedArtifact>> {
if let Some(entry) = state.artifacts.get_mut(key_hex) {
return Some(entry);
}
if !state
.artifact_store_loaded
.load(std::sync::atomic::Ordering::Acquire)
{
let _ = state.artifact_store.load_from_disk();
state
.artifact_store_loaded
.store(true, std::sync::atomic::Ordering::Release);
}
let meta = state.artifact_store.get(key_hex)?;
state
.artifacts
.insert(key_hex.to_string(), CachedArtifact::from_index(meta));
state.artifacts.get_mut(key_hex)
}