#![allow(clippy::missing_errors_doc)]
mod store;
pub use store::{ArtifactIndex, ArtifactStore};
use std::path::Path;
use zccache_core::NormalizedPath;
#[derive(Debug, Clone)]
pub struct ArtifactStoreConfig {
pub cache_dir: NormalizedPath,
pub max_size: u64,
}
pub struct ArtifactStoreLegacy {
config: ArtifactStoreConfig,
}
impl ArtifactStoreLegacy {
pub fn open(config: ArtifactStoreConfig) -> zccache_core::Result<Self> {
std::fs::create_dir_all(&config.cache_dir)?;
Ok(Self { config })
}
#[must_use]
pub fn artifact_path(&self, key: &zccache_hash::ContentHash) -> NormalizedPath {
let shards = key.shard_prefix(2, 1);
self.config
.cache_dir
.join("artifacts")
.join(&shards[0])
.join(&shards[1])
.join(key.to_hex())
}
#[must_use]
pub fn contains(&self, key: &zccache_hash::ContentHash) -> bool {
self.artifact_path(key).exists()
}
#[must_use]
pub fn cache_dir(&self) -> &Path {
&self.config.cache_dir
}
}