From fbd2329d50a9ef2b15c0a6b62e9aa24635c2662a Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 1 Jun 2026 14:51:40 +0900 Subject: internal/pkg: garbage collection This destroys cache entries not referred to by user-specified artifacts and optionally their inputs. Signed-off-by: Ophestra --- internal/pkg/pkg.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'internal/pkg/pkg.go') diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index 883798a4..262ff667 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -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 { -- cgit v1.3.1