From d58c561a067bf55449d82e3297062f2b80547089 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 23 Nov 2026 19:07:39 +0900 Subject: pkg: notify nature of exit This change breaks API. It is seen as an acceptable tradeoff here since this field has no known users other than cmd/mbf, and maintaining compatibility is very ugly in this case. Signed-off-by: Ophestra --- pkg/pkg.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'pkg/pkg.go') diff --git a/pkg/pkg.go b/pkg/pkg.go index 3515f99f..07d467c7 100644 --- a/pkg/pkg.go +++ b/pkg/pkg.go @@ -1785,10 +1785,19 @@ func (e InputError) Unwrap() []error { return errs } +const ( + // NExit indicates a cure implementation being exited. + NExit = iota + // NEnter indicates a cure implementation being entered. + NEnter + // NFault is sent in place of [NExit] for a faulting implementation. + NFault +) + // enterCure must be called before entering an [Artifact] implementation. func (c *Cache) enterCure(a Artifact, curesExempt bool) error { if c.attr.Notify != nil { - c.attr.Notify <- true + c.attr.Notify <- NEnter } if a.IsExclusive() { @@ -1812,9 +1821,13 @@ func (c *Cache) enterCure(a Artifact, curesExempt bool) error { } // exitCure must be called after exiting an [Artifact] implementation. -func (c *Cache) exitCure(a Artifact, curesExempt bool) { +func (c *Cache) exitCure(a Artifact, curesExempt, ok bool) { if c.attr.Notify != nil { - c.attr.Notify <- false + if ok { + c.attr.Notify <- NExit + } else { + c.attr.Notify <- NFault + } } if a.IsExclusive() { @@ -2282,7 +2295,7 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) ( err = closeErr } } - c.exitCure(a, curesExempt) + c.exitCure(a, curesExempt, err == nil) if err != nil { if c.msg.IsVerbose() { c.msg.Verbosef( @@ -2333,7 +2346,7 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) ( return } err = ca.Cure(&t) - c.exitCure(a, curesExempt) + c.exitCure(a, curesExempt, err == nil) if err != nil { if c.msg.IsVerbose() { c.msg.Verbosef( @@ -2505,7 +2518,7 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) ( return } err = ca.Cure(&f) - c.exitCure(a, curesExempt) + c.exitCure(a, curesExempt, err == nil) if !rebuild && err == nil { err = f.linkSubstitute(ids, substitutes) @@ -2749,7 +2762,7 @@ type CacheAttr struct { // Preferred loadavg target, when applicable. Load int // Optional cure entry and exit notification. - Notify chan<- bool + Notify chan<- int // Omit the [lockedfile] lock. skipLock bool -- cgit v1.3.1