Skip to main content

Module cache

Module cache 

Source
Expand description

XDG content-addressable cache with the cache-id integrity-check mechanism.

A snapdir cache is just a local content-addressable store (the same sharded layout as a file:// store): objects live under <cache_dir>/.objects/<h[0..3]>/<h[3..6]>/<h[6..9]>/<h[9..]> and manifests under <cache_dir>/.manifests/<id…>. This module mirrors the cache-side integrity machinery of the Bash oracle:

  • check_snapshot_integrity mirrors _snapdir_check_integrity (snapdir ~L1691): given a snapshot id and a cache directory, assert the manifest is present locally, then verify every file object referenced by the manifest hashes (BLAKE3) to the checksum it is filed under. This is the “verify a cached snapshot by its id” check at the heart of checkout/verify.
  • verify_cache mirrors verify-cache (snapdir ~L1011): enumerate every object under .objects/*/*/*/*, recompute its hash, and compare the actual hash to the expected hash encoded by the object’s own sharded path (the path is the content address). Collect mismatches; when purge is set, delete the corrupt objects.
  • flush_cache mirrors flush-cache (snapdir ~L1061): empty the cache directory, idempotent on a missing dir.

Per the library-purity principle this module performs no terminal I/O and reads no $HOME/XDG/environment for behavior. The cache directory is a parameter; the CLI lane resolves ${XDG_CACHE_HOME:-$HOME/.cache}/snapdir. Hashing is in-process via the Hasher abstraction (the shipped default is BLAKE3); we never shell out to b3sum. The sharded path layout is reused from crate::store (object_path/manifest_path); it is not reimplemented here.

Structs§

CacheReport
Outcome of a whole-cache scan by verify_cache.

Enums§

CacheError
Errors the cache integrity machinery can surface.

Functions§

check_manifest_integrity
Like check_snapshot_integrity but for an already-loaded Manifest.
check_snapshot_integrity
Verifies a cached snapshot by its id — mirrors _snapdir_check_integrity.
flush_cache
Empties the local cache — mirrors snapdir flush-cache.
load_cached_manifest
Loads a cached manifest by snapshot id from cache_dir.
verify_cache
Verifies every object in the cache — mirrors snapdir verify-cache.