diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-06-01 14:51:40 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-06-02 13:28:24 +0900 |
| commit | fbd2329d50a9ef2b15c0a6b62e9aa24635c2662a (patch) | |
| tree | 2c8b0c8c8d16412681c9e758e9121dab022cc008 /internal/pkg/pkg.go | |
| parent | f398f71fa947dbf03587b1a28d314a969aa6b351 (diff) | |
internal/pkg: garbage collection
This destroys cache entries not referred to by user-specified artifacts and optionally their inputs.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/pkg.go')
| -rw-r--r-- | internal/pkg/pkg.go | 22 |
1 files changed, 22 insertions, 0 deletions
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 { |
