pub struct CacheReader<Fs: Filesystem> { /* private fields */ }Expand description
Read-only handle to the cache tree rooted at
<workspace_root>/.haz/cache, parameterised over a
Filesystem backend.
Pairs with crate::CacheWriter: a writer wraps a reader and
adds the mutating operations under the stricter
haz_vfs::WritableFilesystem bound. Consumers that only need
to consult the cache (e.g. haz cache info per AUX-018, the
cache-introspection step of haz why per AUX-014) take a
CacheReader and gain a compile-time guarantee that no write
can sneak in.
Implementations§
Source§impl<Fs: Filesystem> CacheReader<Fs>
impl<Fs: Filesystem> CacheReader<Fs>
Sourcepub fn info(&self) -> Result<CacheInfoReport, CacheInfoError>
pub fn info(&self) -> Result<CacheInfoReport, CacheInfoError>
Walk the cache root and classify every entry per AUX-019.
Idempotent on an absent cache root: when
<workspace_root>/.haz/cache does not exist, returns the
default-zero report rather than an error.
§Errors
Returns CacheInfoError::Io wrapping the underlying
FsError when any filesystem read fails. Manifest parse
failures and schema mismatches are NOT errors: those entries
fold into the CacheInfoReport::corrupt_entries count.
Source§impl<Fs: Filesystem> CacheReader<Fs>
impl<Fs: Filesystem> CacheReader<Fs>
Sourcepub fn lookup(&self, key: &CacheKey) -> Option<Manifest>
pub fn lookup(&self, key: &CacheKey) -> Option<Manifest>
Look up the cache entry for key.
Returns Some(Manifest) on a hit (every consistency
check from CACHE-016 passed), or None on any miss.
Miss reasons enumerated by CACHE-016:
- manifest file absent or unreadable;
- manifest JSON malformed, contains unknown fields, or
uses an unknown
hash_functionvalue; - manifest’s
chapter_revisiondoes not matchcrate::CHAPTER_REVISION; - manifest’s
hash_functiondoes not match the cache’s activehaz_domain::settings::cache::HashAlgo; - any output blob the manifest references is missing, not a regular file, or has a size different from the manifest’s recorded size;
- the captured
stdoutorstderrstream is missing, not a regular file, or has a size different from the manifest’s recordedstdout_len/stderr_len.
Sourcepub fn lookup_status(
&self,
key: &CacheKey,
) -> Result<CacheLookupStatus, CacheLookupError>
pub fn lookup_status( &self, key: &CacheKey, ) -> Result<CacheLookupStatus, CacheLookupError>
Introspecting variant of Self::lookup for AUX-015
step 11.
Performs the same per-entry checks as Self::lookup but
discriminates the outcome into the four spec-named
sub-states. Reuses the same blob / stream verification
(CACHE-015 step 4 / 5), so a hit here is observationally
equivalent to a hit from Self::lookup.
§Errors
Returns CacheLookupError::Io wrapping the underlying
FsError for filesystem errors that are NOT a “missing
entry” shape (those collapse into the
CacheLookupStatus::MissNoEntry /
CacheLookupStatus::MissCorruptEntry variants).
Source§impl<Fs: Filesystem> CacheReader<Fs>
impl<Fs: Filesystem> CacheReader<Fs>
Sourcepub fn new(fs: Fs, workspace_root: &Path, hash_algo: HashAlgo) -> Self
pub fn new(fs: Fs, workspace_root: &Path, hash_algo: HashAlgo) -> Self
Construct a CacheReader handle for the workspace rooted
at workspace_root. The cache root is derived as
<workspace_root>/.haz/cache via layout::cache_root.
hash_algo is the active hash function for this cache
session and is used by lookup to reject entries that were
written under a different algorithm (CACHE-016 step 3).
Sourcepub fn workspace_root(&self) -> &Path
pub fn workspace_root(&self) -> &Path
The absolute path to the workspace root. Restoration
(CACHE-019) needs this to map workspace-anchored
/foo/bar paths recorded in the manifest into real
filesystem paths.
Sourcepub fn cache_root(&self) -> &Path
pub fn cache_root(&self) -> &Path
The absolute path to the cache root,
<workspace_root>/.haz/cache.
Sourcepub fn hash_algo(&self) -> HashAlgo
pub fn hash_algo(&self) -> HashAlgo
The hash function this CacheReader was constructed with.
Trait Implementations§
Source§impl<Fs: Clone + Filesystem> Clone for CacheReader<Fs>
impl<Fs: Clone + Filesystem> Clone for CacheReader<Fs>
Source§fn clone(&self) -> CacheReader<Fs>
fn clone(&self) -> CacheReader<Fs>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more