internal/pkg: garbage collection
All checks were successful
Test / Create distribution (push) Successful in 2m53s
Test / Sandbox (push) Successful in 7m2s
Test / ShareFS (push) Successful in 3m51s
Test / Hakurei (push) Successful in 3m58s
Test / Sandbox (race detector) (push) Successful in 5m32s
Test / Hakurei (race detector) (push) Successful in 6m35s
Test / Flake checks (push) Successful in 2m13s

This destroys cache entries not referred to by user-specified artifacts and optionally their inputs.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-06-01 14:51:40 +09:00
parent f398f71fa9
commit fbd2329d50
4 changed files with 484 additions and 5 deletions

View File

@@ -816,6 +816,28 @@ func (e *ChecksumMismatchError) Error() string {
" instead of " + Encode(e.Want)
}
// LinknamePrefixError describes a malformed linkname to a [Checksum].
type LinknamePrefixError string
func (e LinknamePrefixError) Error() string {
return "linkname " + strconv.Quote(string(e)) + " missing prefix"
}
// readlinkChecksum reads a symbolic link to a dirChecksum entry and saves the
// decoded [Checksum] to the value pointed to by buf. The checksumLinknamePrefix
// is required.
func readlinkChecksum(a *check.Absolute, buf *Checksum) error {
linkname, err := os.Readlink(a.String())
if err != nil {
return nil
}
if !strings.HasPrefix(linkname, checksumLinknamePrefix) {
return LinknamePrefixError(linkname)
}
return Decode(buf, linkname[len(checksumLinknamePrefix):])
}
// ScrubError describes the outcome of a [Cache.Scrub] call where errors were
// found and removed from the underlying storage of [Cache].
type ScrubError struct {