internal/pkg: move outcome dereferencing
Test / Create distribution (push) Successful in 1m1s
Test / Sandbox (push) Successful in 3m3s
Test / Hakurei (push) Successful in 4m0s
Test / ShareFS (push) Successful in 4m7s
Test / Sandbox (race detector) (push) Successful in 5m33s
Test / Hakurei (race detector) (push) Successful in 6m40s
Test / Flake checks (push) Successful in 1m18s
Test / Create distribution (push) Successful in 1m1s
Test / Sandbox (push) Successful in 3m3s
Test / Hakurei (push) Successful in 4m0s
Test / ShareFS (push) Successful in 4m7s
Test / Sandbox (race detector) (push) Successful in 5m33s
Test / Hakurei (race detector) (push) Successful in 6m40s
Test / Flake checks (push) Successful in 1m18s
This prepares substitute computation for shallow extern replacements. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
+31
-15
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user