From 512d9b95bd271c0d4a5e8e8b6fc5d578d847d37e Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sat, 4 Jul 2026 23:46:50 +0900 Subject: [PATCH] internal/pkg: remove status acquisition from extern helper Doing this together just makes it awkward to query status early, having to deal with cleaning up. Signed-off-by: Ophestra --- internal/pkg/pkg.go | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index 489e34f4..78e62e85 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -1881,11 +1881,7 @@ func (c *Cache) tryLocal(id unique.Handle[ID]) (unique.Handle[Checksum], error) } // tryExtern attempts to obtain an [Artifact] outcome from extern. -func (c *Cache) tryExtern( - ctx context.Context, - id unique.Handle[ID], - status *io.ReadCloser, -) ( +func (c *Cache) tryExtern(ctx context.Context, id unique.Handle[ID]) ( unique.Handle[Checksum], error, ) { @@ -1914,12 +1910,7 @@ func (c *Cache) tryExtern( return zeroChecksum, &ChecksumMismatchError{got.Value(), checksum.Value()} } } - - var err error - if status != nil { - *status, err = c.extern.Status(&RContext{common{ctx, c}}, id) - } - return checksum, err + return checksum, nil } // cureMany concurrently collects outcome of multiple [Artifact]. @@ -2254,11 +2245,8 @@ func (c *Cache) cure(a Artifact, curesExempt bool) ( defer f.destroy(&err) - var ( - externChecksum unique.Handle[Checksum] - externStatus io.ReadCloser - ) - if externChecksum, err = c.tryExtern(ctx, id, &externStatus); err != nil { + var externChecksum unique.Handle[Checksum] + if externChecksum, err = c.tryExtern(ctx, id); err != nil { if c.msg.IsVerbose() { c.msg.Verbosef("extern %s: %v", reportName(ca, id), err) } @@ -2266,9 +2254,6 @@ func (c *Cache) cure(a Artifact, curesExempt bool) ( } if externChecksum != zeroChecksum { if checksum != zeroChecksum && externChecksum != checksum { - if externStatus != nil { - _ = externStatus.Close() - } err = &ChecksumMismatchError{externChecksum.Value(), checksum.Value()} if c.msg.IsVerbose() { c.msg.Verbosef("extern %s: %v", reportName(ca, id), err) @@ -2276,6 +2261,14 @@ func (c *Cache) cure(a Artifact, curesExempt bool) ( return } + var externStatus io.ReadCloser + c.externMu.RLock() + externStatus, err = c.extern.Status(&RContext{common{ctx, c}}, id) + c.externMu.RUnlock() + if err != nil { + return + } + checksum = externChecksum checksums = Encode(checksum.Value()) checksumPathname = c.base.Append(