From 8efffd72f4c5a0f241075fd13e4d07d71fd7fde8 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 6 Jan 2026 04:24:54 +0900 Subject: [PATCH] internal/pkg: destroy temp during deferred cleanup This avoids missing the cleanup when cure returns an error. Signed-off-by: Ophestra --- internal/pkg/pkg.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index 85a9f82..39563c9 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -181,7 +181,7 @@ type Kind uint64 const ( // KindHTTPGet is the kind of [Artifact] returned by [NewHTTPGet]. KindHTTPGet Kind = iota - // KindTar is the kind of artifact returned by [NewTar]. + // KindTar is the kind of [Artifact] returned by [NewTar]. KindTar ) @@ -829,6 +829,11 @@ func (c *Cache) Cure(a Artifact) ( temp: c.base.Append(dirTemp, ids), } defer func() { + if chmodErr, removeErr := removeAll(cc.temp); chmodErr != nil || removeErr != nil { + err = errors.Join(err, chmodErr, removeErr) + return + } + if err != nil { chmodErr, removeErr := removeAll(cc.work) if chmodErr != nil || removeErr != nil { @@ -844,11 +849,6 @@ func (c *Cache) Cure(a Artifact) ( return } cc.cache = nil - if chmodErr, removeErr := removeAll(cc.temp); chmodErr != nil || removeErr != nil { - err = errors.Join(err, chmodErr, removeErr) - return - } - var fi os.FileInfo if fi, err = os.Lstat(cc.work.String()); err != nil { if errors.Is(err, os.ErrNotExist) {