Skip to main content

verify_cache

Function verify_cache 

Source
pub fn verify_cache(
    cache_dir: &Path,
    purge: bool,
    hasher: &dyn Hasher,
) -> Result<CacheReport, CacheError>
Expand description

Verifies every object in the cache — mirrors snapdir verify-cache.

Enumerates every object at <cache_dir>/.objects/*/*/*/*, recomputes its hash via hasher, and compares it to the expected checksum encoded by the object’s own sharded path (the path is the content address). The expected checksum is reconstructed exactly as the oracle does (sed 's| .*.objects/| |; s|/||g'): concatenate the four path segments after .objects/ with the separators removed.

Returns a CacheReport: how many objects were checked, which were corrupt, and — when purge is set — which were deleted. An absent or empty .objects directory is a clean pass with zero checked, matching the oracle’s test -d "${cache_dir}/.objects" || return 0.

§Errors

  • CacheError::Io on a directory-traversal or read failure (other than the .objects directory simply being absent, which is a clean pass).