review: rebuild a file the mesh once wrote whole, keep links, give back a missing line end, and release a hold only after the write (hq issue 128)
This commit is contained in:
+22
-3
@@ -52,6 +52,8 @@ type Outcome struct {
|
||||
wrote string
|
||||
// into is what a file written into held before the mesh's keys (novox/hq ADR 0102).
|
||||
into *store.Into
|
||||
// kept is where this apply kept the original of a file it wrote over (novox/hq ADR 0100).
|
||||
kept string
|
||||
// reads is, for a container, the digest of each file it was created reading, by path — so
|
||||
// the next apply can say which one changed (novox/hq 04-ISSUES/103).
|
||||
reads map[string]string
|
||||
@@ -441,6 +443,16 @@ func ApplyKeeping(
|
||||
continue
|
||||
}
|
||||
|
||||
// Where the original of what this file replaced was kept, carried for as long as the
|
||||
// resource is recorded: kept by this apply, by a hold its module's cutover ends, or before.
|
||||
held, wasHeld := known.HeldAt(resource.Identity())
|
||||
kept := outcome.kept
|
||||
if kept == "" && wasHeld {
|
||||
kept = held.Kept
|
||||
}
|
||||
if kept == "" {
|
||||
kept = was.Kept
|
||||
}
|
||||
// Only now. The record follows the fact, never leads it.
|
||||
known.Record(store.Applied{
|
||||
Origin: origin,
|
||||
@@ -448,13 +460,19 @@ func ApplyKeeping(
|
||||
Target: outcome.Target, AppliedAt: time.Now().UTC(),
|
||||
Wrote: outcome.wrote,
|
||||
Into: outcome.into,
|
||||
Kept: kept,
|
||||
Reads: outcome.reads,
|
||||
Holds: holds(resource),
|
||||
})
|
||||
// Its module has been taken, and what was held for it is now the mesh's.
|
||||
if held, wasHeld := known.HeldAt(resource.Identity()); wasHeld {
|
||||
// Its module has been taken, and what was held for it is now the mesh's. A file written
|
||||
// into replaced nothing that was found, so its outcome says what the write did, not that
|
||||
// a cutover happened; its hold from when it was declared whole goes all the same — here,
|
||||
// after the write worked, so a failed one keeps the hold and where its original is.
|
||||
if wasHeld {
|
||||
known.Release(held.ID)
|
||||
outcome.Detail = takenDetail(held)
|
||||
if f, isFile := resource.(*declaration.File); !isFile || f.Into == "" {
|
||||
outcome.Detail = takenDetail(held)
|
||||
}
|
||||
}
|
||||
if svc, ok := resource.(*declaration.Service); ok && svc.TakesOver != nil && report.Tunnel != nil {
|
||||
// The found interface is down and the mesh's is up in its place: the tunnel changed
|
||||
@@ -840,6 +858,7 @@ func applyFile(r *declaration.File, previous store.Applied, unseal Unseal, keepF
|
||||
default:
|
||||
out.Action = "unchanged"
|
||||
}
|
||||
out.kept = kept
|
||||
if kept != "" {
|
||||
if out.Detail != "" {
|
||||
out.Detail += "; "
|
||||
|
||||
Reference in New Issue
Block a user