From f5e9a0c04e0373ac527f180bb9f9ec010732038f Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sat, 23 May 2026 01:31:13 +0900 Subject: [PATCH] internal/pkg: destroy new substitution status on fault This avoids leaving behind the substitution status path of a faulted cure. Signed-off-by: Ophestra --- internal/pkg/pkg.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index d2565c37..883798a4 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -155,7 +155,7 @@ type TContext struct { // Target [Artifact] encoded identifier. ids string // Pathname status was created at. - statusPath *check.Absolute + statusPath, statusSPath *check.Absolute // File statusHeader and logs are written to. status *os.File // Error value during prepareStatus. @@ -258,6 +258,11 @@ func (t *TContext) destroy(errP *error) { ), 10), ).String(), )) + if t.statusSPath != nil { + t.cache.checksumMu.Lock() + *errP = errors.Join(*errP, os.Remove(t.statusSPath.String())) + t.cache.checksumMu.Unlock() + } } t.status = nil } @@ -1957,7 +1962,7 @@ func (c *Cache) cure(a Artifact, curesExempt bool) ( t := TContext{ c.base.Append(dirWork, ids), c.base.Append(dirTemp, ids), - ids, nil, nil, nil, + ids, nil, nil, nil, nil, common{ctx, c}, } switch ca := a.(type) { @@ -2049,13 +2054,19 @@ func (c *Cache) cure(a Artifact, curesExempt bool) ( } err = ca.Cure(&f) if err == nil && f.status != nil { + statusS := c.base.Append( + dirStatus, + substitutes, + ) + c.checksumMu.Lock() err = os.Link(c.base.Append( dirStatus, ids, - ).String(), c.base.Append( - dirStatus, - substitutes, - ).String()) + ).String(), statusS.String()) + c.checksumMu.Unlock() + if err == nil { + f.statusSPath = statusS + } } c.exitCure(a, curesExempt) if err != nil {