aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pkg')
-rw-r--r--internal/pkg/pkg.go46
1 files changed, 31 insertions, 15 deletions
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index d8e059bd..6bf34b2a 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -1851,6 +1851,35 @@ func (r *RContext) NewMeasuredReader(
return r.cache.newMeasuredReader(rc, checksum)
}
+// tryChecksum dereferences a symlink to a cure outcome.
+func (c *Cache) tryChecksum(pathname *check.Absolute) (
+ checksum unique.Handle[Checksum],
+ err error,
+) {
+ _, err = os.Lstat(pathname.String())
+ if err == nil {
+ var name string
+ if name, err = os.Readlink(pathname.String()); err != nil {
+ return
+ }
+ buf := c.getIdentBuf()
+ err = Decode((*Checksum)(buf[:]), filepath.Base(name))
+ if err == nil {
+ checksum = unique.Make(Checksum(buf[:]))
+ }
+ c.putIdentBuf(buf)
+ }
+ return
+}
+
+// tryLocal attempts to obtain an [Artifact] outcome from the filesystem.
+func (c *Cache) tryLocal(id unique.Handle[ID]) (unique.Handle[Checksum], error) {
+ return c.tryChecksum(c.base.Append(
+ dirIdentifier,
+ Encode(id.Value()),
+ ))
+}
+
// tryExtern attempts to obtain an [Artifact] outcome from extern.
func (c *Cache) tryExtern(
ctx context.Context,
@@ -1928,21 +1957,8 @@ func (c *Cache) cure(a Artifact, curesExempt bool) (
defer func() { c.finaliseIdent(done, id, checksum, err) }()
}
- _, err = os.Lstat(pathname.String())
- if err == nil {
- var name string
- if name, err = os.Readlink(pathname.String()); err != nil {
- return
- }
- buf := c.getIdentBuf()
- err = Decode((*Checksum)(buf[:]), filepath.Base(name))
- if err == nil {
- checksum = unique.Make(Checksum(buf[:]))
- }
- c.putIdentBuf(buf)
- return
- }
- if !errors.Is(err, os.ErrNotExist) {
+ checksum, err = c.tryChecksum(pathname)
+ if err == nil || !errors.Is(err, os.ErrNotExist) {
return
}