Merged
Conversation
Add CacheEntry type and three new methods to image.Cache: - List() returns metadata for all cached rootfs entries including digest, size, last-used time, and which image refs point to each. - GC() removes rootfs entries not referenced by any ref index entry (reachability-based, unlike the time-based Evict). - Purge() removes the entire cache directory. Extend the ref index format to store the original image reference alongside the digest (imageRef\tdigest), enabling List to report human-readable ref names. getRef handles both legacy and extended formats for backward compatibility. Add LayerCache.Size() for reporting total layer cache disk usage. Ref: stacklok/brood-box#84 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- GC now aborts instead of deleting everything when the refs directory is unreadable (liveDigests returns error instead of nil map) - Filter empty imageRef from Refs in buildRefMap (legacy-format refs no longer produce empty strings in CacheEntry.Refs) - Harmonize pathFor to use Replace(..., 1) matching dirNameToDigest - Add path traversal defense in pathFor rejecting digests with / or .. - Fix ModTime doc comment to be more precise - Add tests: GC with non-existent dir, multiple refs to same digest, corrupt ref files - Tighten List size assertion to exact byte count Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add cache management methods to
image.Cacheto support thebbox cacheCLI subcommand (stacklok/brood-box#84).List() ([]CacheEntry, error)— enumerate all cached rootfs entries with digest, size, last-used time, and which image refs point to eachGC() (int, error)— reachability-based garbage collection: removes rootfs entries not referenced by any ref index entryPurge() error— removes the entire cache directoryLayerCache.Size() (int64, error)— reports total layer cache disk usageRef index enhancement
putRefnow storesimageRef\tdigest\n(extended format) soListcan report human-readable image references.getRefhandles both legacy (digest-only) and extended formats for backward compatibility.Safety
GCaborts (returns error) if the refs directory exists but is unreadable, preventing accidental deletion of all entriespathFornow validates digests and rejects path separators and..components (defense-in-depth)pathForusesReplace(..., 1)to matchdirNameToDigestfor symmetric round-tripsGCand concurrentPullis documented — consequence is a cache miss, not data lossTest plan
CGO_ENABLED=0 go test -v ./image/)🤖 Generated with Claude Code