aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/pkg.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pkg/pkg.go')
-rw-r--r--internal/pkg/pkg.go22
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 {