Apply a module again only for a newly missing resource, leave filled files out of the record check, and say when the applied state cannot be read (issue 1945)

This commit is contained in:
2026-10-25 11:04:08 +01:00
parent c46937da04
commit 43d1c2456f
3 changed files with 82 additions and 4 deletions
+22 -1
View File
@@ -1334,6 +1334,7 @@ const (
// anyway. A statement the bus did not take is said at the next look. It reads; it never acts (ADR 0240
// rule 6) — but for going on with a take act stopped at its bound (ADR 0328 §7), which runs beside it.
func judgeWhatRuns(ctx context.Context, j *liveness.Judge, queue *link.Session, say link.Announce, reapply func(modules ...string)) {
var missingBefore map[string]bool
ticker := time.NewTicker(liveness.LookEvery)
defer ticker.Stop()
var lastSaid time.Time
@@ -1421,7 +1422,9 @@ func judgeWhatRuns(ctx context.Context, j *liveness.Judge, queue *link.Session,
}
// A resource the machine does not have at all is made again: its module's composition applied anew (issue
// 1945), once each time the statement changes, never on a clock.
if m := missingModules(st); len(m) > 0 && reapply != nil {
var m []string
m, missingBefore = newlyMissing(missingBefore, st)
if len(m) > 0 && reapply != nil {
say(fmt.Sprintf("applying %s again: a resource it declares is not on this machine", strings.Join(m, ", ")))
reapply(m...)
}
@@ -2101,3 +2104,21 @@ func missingModules(st liveness.Statement) []string {
sort.Strings(out)
return out
}
// newlyMissing are the modules of the resources a statement says missing that the last statement acted on did not, each
// once, sorted, and the missing resources now: a resource still missing is not acted on again, so a module whose
// resource cannot be made is not applied at every change of the statement (the review of issue 1945).
func newlyMissing(last map[string]bool, st liveness.Statement) ([]string, map[string]bool) {
now := map[string]bool{}
var fresh liveness.Statement
for _, r := range st.Resources {
if !r.Missing {
continue
}
now[r.ID] = true
if !last[r.ID] {
fresh.Resources = append(fresh.Resources, r)
}
}
return missingModules(fresh), now
}