Review fix 3: every install deletes the off-site end record — one point, SaveAppConfig (D72)
A `.fab` import installed the app and its end record survived; the restore that installs from a unit had the same hole. Only DeployStack deleted it. - stacks.SaveAppConfig, the only writer of an installed app's app.yaml, calls noteAppInstalled when the record says deployed (a hook per stacks directory, registered by SetMigrationDeps). A source pin lists every place that sets Deployed or writes an app.yaml; a new writer fails it. - The living check is stacks.Manager.IsLivingApp (wired in main.go): the protected list, the manager's list (deployed, being deployed, protected) and the app's record on disk — an installed app the manager does not list is living. Tested by behaviour. Tests seen red before the fix; 8 mutations seen red (felhom.eu documentation/audits/build-release-4-2026-11-15/A/redproof-review-3.txt). Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
3928c3db28
commit
c7e4ec9b5e
7 files changed
+312
-14
No files matched your search
@@ -2,6 +2,17 @@
|
||||
|
||||
**MinAgent: 0.158.1** (unchanged — nothing here asks the agent for anything)
|
||||
|
||||
- **Review fix 3 (2026-11-15): EVERY install deletes the off-site end record, not only a deploy.** A `.fab` import
|
||||
(`SaveImportedAppConfig`) installed the app and the record survived; the restore that installs from a unit
|
||||
(`PersistUnitRedeployConfigGate`) had the same hole. The rule now sits at ONE point: `stacks.SaveAppConfig`, the
|
||||
only writer of an installed app's `app.yaml`, calls `noteAppInstalled` when the record says deployed (a hook per
|
||||
stacks directory, registered by `SetMigrationDeps`). `TestD72_TheInstallWritersAreListed` lists every place that
|
||||
sets `Deployed` or writes an `app.yaml`; a new writer fails it. **The living check is a method now**,
|
||||
`stacks.Manager.IsLivingApp` (wired in `main.go`), and reads three places: the protected list, the manager's list
|
||||
(deployed, being deployed, protected) and the app's record on disk — an installed app the manager does not list is
|
||||
living. Tests `TestD72_AnImportDeletesTheEndRecord`, `TestD72_ARestoreIntoAnInstallDeletesTheEndRecord`,
|
||||
`TestD72_ADriveFlipRecordWriteDeletesTheEndRecord`, `TestD72_SaveAppConfigIsTheOnePoint`, `TestD72_IsLivingApp` —
|
||||
the first four seen red before the fix; 8 mutations seen red (felhom.eu `…/A/redproof-review-3.txt`).
|
||||
- **Review fix 2 (2026-11-15): a take-back or an install DURING the clean-up window no longer loses the copies.** The
|
||||
due records and the candidates were read once, before the hub was asked, and never again before the forget — so
|
||||
„Mégis megtartom” (or an install) while the hub answered still deleted, after the page had said „kept”. The window
|
||||
|
||||
@@ -282,7 +282,7 @@
|
||||
| `ConfigRefresher.Reconcile` | controller/internal/report/config_refresh.go | `(ackVersion int)` | Pull-based config refresh | Re-pulls controller.yaml (re-merging local_api), then graceful self-restart; first-run = baseline, no restart |
|
||||
| `offsiteapply.HubRegistrar` / `HubWindowClient` / `PinnedProber` (v0.289.0, decisions 68–69) | controller/internal/offsiteapply/seams.go | `Register(ctx,pub)(fp,err)` · `Confirm` · `MoveAside` · `Open/Close` window · `Probe(ctx,host,user,port,kh,privPEM) bool` | EVERY off-site key install, the hub move-aside, the clean-up window | **The box never handles the sub-account password** — there is no consume path any more. `PinnedProber` is a POSITIVE observable (exit 0 + rclone output); "authenticates" is NOT enough — an unpinned key authenticates and can delete. |
|
||||
| `Manager.offsiteWindowRetention` + `offsiteGuard` (v0.289.0, R-822) | controller/internal/backup/offbox_window.go | `(ctx, base, env, why)` · pure `(all, plan, now, newestAllowed, max) (ids, refuse)` | THE retention step for both callers (after a run, over quota) | Pinned tier: no window → nothing deleted; the guard runs BEFORE any forget; "young" = fewer than `keepDaily` CALENDAR days old (v0.294.0, R-867 — the line is built from the same constants as `retentionPolicy`; never an hour count); a young snapshot superseded the same day is EXCLUDED, any other young removal / future date / plan above `max_remove` REFUSES; tests run restic 0.14.0's policy itself (`restic0140Plan`, proven identical to the binary); forget is by explicit ids, oldest first. A due abandonment goes to `OffsiteAbandonClient` (hub, 7-day wait). NAS tier: the old SP-2 policy, unchanged. |
|
||||
| `Manager.StartOffsiteEnd` / `KeepOffsiteCopies` + `settings.OffsiteEnd` (D72/D84, felhom.eu `07` §8.2f; built, not released) | controller/internal/backup/offbox_ended.go, controller/internal/settings/offsite_ends.go | `StartOffsiteEnd(app) (rec, created, err)` · pure `dueOffsiteEnds`, `endedCandidates`, `endedToRemove` | The off-site copies of a removed app end 30 days after „delete backup data”: the record, the press, the take-back, and the ended apps' ids in the weekly window | **NO RECORD = NO DELETION.** `StartOffsiteEnd` is the ONLY writer (it sends the household's one mail when it really wrote); an install deletes the record (`stacks.DeployStack`). The window removes an ended app's snapshot only when every app tag on it is a due record, the hub sent its id back (`OffsiteWindow.EndedAllowed`) and the box named it in the same window. `SetOffsiteEndLiving` not wired → nothing is ever due. Only on the hub-provisioned (pinned) tier. |
|
||||
| `Manager.StartOffsiteEnd` / `KeepOffsiteCopies` + `settings.OffsiteEnd` (D72/D84, felhom.eu `07` §8.2f; built, not released) | controller/internal/backup/offbox_ended.go, controller/internal/settings/offsite_ends.go | `StartOffsiteEnd(app) (rec, created, err)` · pure `dueOffsiteEnds`, `endedCandidates`, `endedToRemove` | The off-site copies of a removed app end 30 days after „delete backup data”: the record, the press, the take-back, and the ended apps' ids in the weekly window | **NO RECORD = NO DELETION.** `StartOffsiteEnd` is the ONLY writer (it sends the household's one mail when it really wrote); an install deletes the record (`stacks.DeployStack`). The window removes an ended app's snapshot only when every app tag on it is a due record, the hub sent its id back (`OffsiteWindow.EndedAllowed`) and the box named it in the same window. `SetOffsiteEndLiving` not wired → nothing is ever due (wired to `stacks.Manager.IsLivingApp`). Only on the hub-provisioned (pinned) tier. **„The app became installed” is ONE point: `stacks.SaveAppConfig` → `noteAppInstalled`** — never add a second writer of an app's `app.yaml` (`TestD72_TheInstallWritersAreListed`). The window reads the records again right before the forget (`lastLookAtEnded`). |
|
||||
| `offsiteapply.SettleProvider` / `SettleFunc` / `Bridge.AwaitSettle` / `ReconcileWhenSettled` (R-71a, v0.162.0) | controller/internal/offsiteapply/offsiteapply.go + seams.go | `SettleState() (version, floor string, updateRunning, floorKnown bool)` | THE settle-gate: defers the offsite one-time-password consume past a managed day-0 floor-update (the F10 race). Wire the `SettleFunc` adapter over `updater.GetFloor()`/`IsUpdateRunning()` — **the updater's knowledge is the ONE floor source; never fetch the floor a second way**. Gate ONLY the bridge goroutine, and only when an updater exists (nil `Settle` = reconcile immediately). Bounds `settlePoll`/`settleFloorSubBound`/`settleOverallBound`; the floor is in-memory (report-ACK-derived, ~5–10 s), NOT persisted → unknown until the first ACK on any restart. Inject `Now`/`Sleep` in tests (no real sleeps). B′: at/above-floor GOes on the first poll, zero wait. Do NOT touch the consume/persist order or the 404 contract — ordering only |
|
||||
| `bootstrap.MaybeIngest` / `RefreshConfig` | controller/internal/bootstrap/bootstrap.go | bootstrap.json → controller.yaml | Day-0 + refresh | Overwrites controller.yaml, NEVER settings.json |
|
||||
| `api.GracefulSelfRestart` | controller/internal/api/selfrestart.go | `(logger)` | Controller self-restart | Detached exit; bootstrap unit re-runs the image |
|
||||
|
||||
@@ -1611,13 +1611,7 @@ func main() {
|
||||
// D72 / D84 (`07` §8.2f): the off-site copies of a removed app. (1) „Living": installed right now, or one of
|
||||
// the box's own protected stacks — such an app's end record is never due, and it cannot get one. Without
|
||||
// this seam nothing is ever due (backup/offbox_ended.go). (2) The household's one mail per press.
|
||||
backupMgr.SetOffsiteEndLiving(func(app string) bool {
|
||||
if cfg.IsProtectedStack(app) {
|
||||
return true
|
||||
}
|
||||
st, ok := stackMgr.GetStack(app)
|
||||
return ok && (st.Deployed || st.Deploying || st.Protected)
|
||||
})
|
||||
backupMgr.SetOffsiteEndLiving(stackMgr.IsLivingApp)
|
||||
backupMgr.SetOffsiteEndNotify(func(rec settings.OffsiteEnd) {
|
||||
notifier.NotifyOffsiteEndScheduled(rec.App, rec.RemovedAt, rec.EndsAt, rec.Ends().Local())
|
||||
})
|
||||
|
||||
@@ -535,7 +535,7 @@ func TestD72_MainWiresTheLivingCheck(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
src := string(raw)
|
||||
for _, want := range []string{"backupMgr.SetOffsiteEndLiving(func(app string) bool {", "cfg.IsProtectedStack(app)", "st.Deployed || st.Deploying || st.Protected",
|
||||
for _, want := range []string{"backupMgr.SetOffsiteEndLiving(stackMgr.IsLivingApp)",
|
||||
"backupMgr.SetOffsiteEndNotify(func(rec settings.OffsiteEnd) {", "notifier.NotifyOffsiteEndScheduled(rec.App, rec.RemovedAt, rec.EndsAt"} {
|
||||
if !strings.Contains(src, want) {
|
||||
t.Errorf("main.go lacks %q", want)
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
package stacks
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
|
||||
)
|
||||
|
||||
// Review of 2026-11-15, finding 3: an IMPORT installed the app and its off-site end record survived — only
|
||||
// DeployStack deleted it. The rule „an install of the same app deletes the record” (`07` §8.2f) now sits at ONE
|
||||
// point every install passes: SaveAppConfig, the only writer of an installed app's app.yaml. A test per path, and a
|
||||
// source pin that lists the writers so a new one cannot appear unseen.
|
||||
// RED-PROOF: felhom.eu/documentation/audits/build-release-4-2026-11-15/A/redproof-review-3.txt.
|
||||
|
||||
func endRecordManager(t *testing.T) (*Manager, *settings.Settings, string) {
|
||||
t.Helper()
|
||||
m := gateManager(t, gatedYml)
|
||||
sett, err := settings.Load(filepath.Join(t.TempDir(), "settings.json"), log.New(io.Discard, "", 0))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.SetMigrationDeps(sett, func() bool { return false })
|
||||
if _, _, err := sett.StartOffsiteEnd("gapp", time.Now().Add(-29*24*time.Hour)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := sett.StartOffsiteEnd("otherapp", time.Now().Add(-29*24*time.Hour)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.mu.Lock()
|
||||
dir := filepath.Dir(m.stacks["gapp"].ComposePath)
|
||||
m.mu.Unlock()
|
||||
return m, sett, dir
|
||||
}
|
||||
|
||||
func assertEndRecordGone(t *testing.T, sett *settings.Settings, how string) {
|
||||
t.Helper()
|
||||
if rec, ok := sett.GetOffsiteEnd("gapp"); ok {
|
||||
t.Fatalf("%s: the app is installed again and its off-site end record survives (%+v) — the window would delete a living app's history", how, rec)
|
||||
}
|
||||
if _, ok := sett.GetOffsiteEnd("otherapp"); !ok {
|
||||
t.Fatalf("%s: another app's record was deleted", how)
|
||||
}
|
||||
}
|
||||
|
||||
// PATH: a `.fab` import.
|
||||
func TestD72_AnImportDeletesTheEndRecord(t *testing.T) {
|
||||
m, sett, dir := endRecordManager(t)
|
||||
if _, err := m.SaveImportedAppConfig(dir, map[string]string{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertEndRecordGone(t, sett, "import")
|
||||
}
|
||||
|
||||
// PATH: a restore that installs the app again from its recovery unit („use my kept data”, the off-site reinstall).
|
||||
func TestD72_ARestoreIntoAnInstallDeletesTheEndRecord(t *testing.T) {
|
||||
m, sett, _ := endRecordManager(t)
|
||||
if err := m.PersistUnitRedeployConfig("gapp", map[string]string{"DOMAIN": "example.hu", "SUBDOMAIN": "gapp"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertEndRecordGone(t, sett, "unit restore")
|
||||
}
|
||||
|
||||
// PATH: the data move's record write (it sets Deployed on an app.yaml it loaded).
|
||||
func TestD72_ADriveFlipRecordWriteDeletesTheEndRecord(t *testing.T) {
|
||||
m, sett, dir := endRecordManager(t)
|
||||
if err := os.WriteFile(filepath.Join(dir, "app.yaml"), []byte("deployed: false\nenv: {}\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := m.persistDriveFlip("gapp", "/mnt/felhom-drives/x"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertEndRecordGone(t, sett, "drive flip")
|
||||
}
|
||||
|
||||
// THE ONE POINT: any write of an app.yaml that says „deployed” — whoever makes it — deletes the record; a write that
|
||||
// says „not deployed” (the install's transitional record, a removal's) does not.
|
||||
func TestD72_SaveAppConfigIsTheOnePoint(t *testing.T) {
|
||||
m, sett, dir := endRecordManager(t)
|
||||
if err := SaveAppConfig(dir, &AppConfig{Deployed: false, Env: map[string]string{}}, m.encKey, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := sett.GetOffsiteEnd("gapp"); !ok {
|
||||
t.Fatal("a „not deployed” write deleted the end record")
|
||||
}
|
||||
if err := SaveAppConfig(dir, &AppConfig{Deployed: true, Env: map[string]string{}}, m.encKey, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertEndRecordGone(t, sett, "SaveAppConfig(Deployed: true)")
|
||||
// a second manager (another stacks directory) is not touched by this one's writes
|
||||
m2, sett2, _ := endRecordManager(t)
|
||||
if err := SaveAppConfig(dir, &AppConfig{Deployed: true, Env: map[string]string{}}, m.encKey, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := sett2.GetOffsiteEnd("gapp"); !ok {
|
||||
t.Fatal("a write in ANOTHER stacks directory deleted this box's record")
|
||||
}
|
||||
_ = m2
|
||||
}
|
||||
|
||||
// THE SOURCE PIN: who can make an app „installed”. Every writer of an app's app.yaml and every place that sets
|
||||
// Deployed is listed here. A new one fails this test: route it through SaveAppConfig (which deletes the off-site end
|
||||
// record) or say here why it is not an install.
|
||||
func TestD72_TheInstallWritersAreListed(t *testing.T) {
|
||||
root := filepath.Join("..", "..")
|
||||
find := func(re *regexp.Regexp) []string {
|
||||
var out []string
|
||||
for _, top := range []string{"internal", "cmd"} {
|
||||
_ = filepath.Walk(filepath.Join(root, top), func(p string, fi os.FileInfo, err error) error {
|
||||
if err != nil || fi.IsDir() || !strings.HasSuffix(p, ".go") || strings.HasSuffix(p, "_test.go") {
|
||||
return nil
|
||||
}
|
||||
raw, rerr := os.ReadFile(p)
|
||||
if rerr != nil {
|
||||
t.Fatal(rerr)
|
||||
}
|
||||
if n := len(re.FindAll(raw, -1)); n > 0 {
|
||||
rel, _ := filepath.Rel(root, p)
|
||||
out = append(out, filepath.ToSlash(rel))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
for _, c := range []struct {
|
||||
what string
|
||||
re string
|
||||
want []string
|
||||
}{
|
||||
{"a struct literal that says Deployed: true", `\bDeployed:\s*true\b`, []string{
|
||||
"internal/backup/recovery_unit.go", // the stripped copy INSIDE a recovery unit — not the app's own app.yaml
|
||||
"internal/stacks/deploy.go", // DeployStack, PersistUnitRedeployConfigGate → SaveAppConfig
|
||||
"internal/stacks/import_record.go", // SaveImportedAppConfig → SaveAppConfig
|
||||
"internal/stacks/install_interrupted.go", // a comment only: it reads the record, it writes none
|
||||
}},
|
||||
{"an assignment cfg.Deployed = true", `\bcfg\.Deployed = true\b`, []string{
|
||||
"internal/stacks/migrate.go", // persistDriveFlip → SaveAppConfig
|
||||
}},
|
||||
{"a direct write of an app.yaml", `WriteFile\([^\n]*"app\.yaml"`, []string{
|
||||
"internal/backup/offbox_reconstitute.go", // `install_id` only, into a scratch folder — never „deployed”
|
||||
}},
|
||||
{"the app.yaml writer itself", `filepath\.Join\(stackDir, "app\.yaml"\)\s*\n\s*header`, []string{
|
||||
"internal/stacks/deploy.go", // SaveAppConfig
|
||||
}},
|
||||
} {
|
||||
if got := find(regexp.MustCompile(c.re)); strings.Join(got, ",") != strings.Join(c.want, ",") {
|
||||
t.Errorf("%s:\n found %v\n listed %v\nA new writer must go through SaveAppConfig, or be listed here with the reason it is not an install.", c.what, got, c.want)
|
||||
}
|
||||
}
|
||||
// and SaveAppConfig really is the point
|
||||
raw, err := os.ReadFile("deploy.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !regexp.MustCompile(`(?s)func SaveAppConfig\(.*?noteAppInstalled\(stackDir\)`).Match(raw) {
|
||||
t.Error("SaveAppConfig does not call noteAppInstalled — no install path deletes the off-site end record")
|
||||
}
|
||||
}
|
||||
|
||||
// THE LIVING CHECK, by behaviour (main.go wires exactly this method into the clean-up window): an installed app, an
|
||||
// app being installed, a protected stack and an installed app the manager does NOT list are all living; a catalog
|
||||
// app that is not installed and an app that left the box are not.
|
||||
func TestD72_IsLivingApp(t *testing.T) {
|
||||
m := gateManager(t, gatedYml)
|
||||
m.cfg.Stacks.Protected = []string{"traefik"}
|
||||
set := func(fn func(s *Stack)) {
|
||||
m.mu.Lock()
|
||||
fn(m.stacks["gapp"])
|
||||
m.mu.Unlock()
|
||||
}
|
||||
if m.IsLivingApp("gapp") {
|
||||
t.Fatal("a catalog app that is NOT installed reads as living — its end could never be carried out")
|
||||
}
|
||||
if m.IsLivingApp("left-the-box") {
|
||||
t.Fatal("an app with no template and no record reads as living")
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
prep func()
|
||||
app string
|
||||
}{
|
||||
{"installed", func() { set(func(s *Stack) { s.Deployed = true }) }, "gapp"},
|
||||
{"being installed (Deploying)", func() { set(func(s *Stack) { s.Deployed, s.Deploying = false, true }) }, "gapp"},
|
||||
{"marked protected in the list", func() { set(func(s *Stack) { s.Deploying, s.Protected = false, true }) }, "gapp"},
|
||||
{"a protected stack by the config, not in the list", func() { set(func(s *Stack) { s.Protected = false }) }, "traefik"},
|
||||
{"always-protected samba", func() {}, "samba"},
|
||||
{"the empty name", func() {}, ""},
|
||||
{"a path, not a name", func() {}, "../gapp"},
|
||||
} {
|
||||
c.prep()
|
||||
if !m.IsLivingApp(c.app) {
|
||||
t.Errorf("%s: %q does not read as living", c.name, c.app)
|
||||
}
|
||||
}
|
||||
set(func(s *Stack) { s.Deployed, s.Deploying, s.Protected = false, false, false })
|
||||
if m.IsLivingApp("gapp") {
|
||||
t.Fatal("fixture: gapp must be not-installed again")
|
||||
}
|
||||
// An installed app the manager does NOT list (GetStack finds nothing): its record on disk says it is installed.
|
||||
orphan := filepath.Join(m.cfg.Paths.StacksDir, "orphanapp")
|
||||
if err := os.MkdirAll(orphan, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(orphan, "app.yaml"), []byte("deployed: true\nenv: {}\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, listed := m.GetStack("orphanapp"); listed {
|
||||
t.Fatal("fixture: orphanapp must not be in the manager's list")
|
||||
}
|
||||
if !m.IsLivingApp("orphanapp") {
|
||||
t.Fatal("an INSTALLED app the manager does not list reads as removed — the window could end its copies")
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(orphan, "app.yaml"), []byte("deployed: false\nenv: {}\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m.IsLivingApp("orphanapp") {
|
||||
t.Fatal("a record that says not deployed reads as living")
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/appbackup"
|
||||
@@ -568,11 +569,8 @@ func (m *Manager) DeployStack(req DeployRequest) (string, error) {
|
||||
// D72 (`07` §8.2f): an install of the same app ENDS its pending off-site end record — the household uses the
|
||||
// app again, and its old copies are restore sources again. Here, at the first write of the install: a deploy
|
||||
// that was refused above changed nothing. Pinned by TestD72_AnInstallDeletesTheEndRecord.
|
||||
if m.settings != nil {
|
||||
if _, cerr := m.settings.CancelOffsiteEnd(req.StackName, "the app is installed again"); cerr != nil {
|
||||
m.logger.Printf("[WARN] [stacks] deploy %s: its off-site end record could not be deleted (%v) — the clean-up window skips an installed app anyway", req.StackName, cerr)
|
||||
}
|
||||
}
|
||||
// (This first write says „not deployed yet”, so SaveAppConfig's own call does not fire; the install has begun.)
|
||||
m.appInstalledAgain(req.StackName)
|
||||
|
||||
// Debug: log final env var keys (not values)
|
||||
envKeys := make([]string, 0, len(env))
|
||||
@@ -1225,9 +1223,74 @@ func SaveAppConfig(stackDir string, cfg *AppConfig, encKey []byte, sensitiveVars
|
||||
return fmt.Errorf("renaming %s to %s: %w", tmpPath, path, err)
|
||||
}
|
||||
log.Printf("[INFO] [stacks] SaveAppConfig: saved config for %s", filepath.Base(stackDir))
|
||||
// D72 (`07` §8.2f; review of 2026-11-15): THE ONE POINT „the app became installed”. Every install — a deploy, a
|
||||
// `.fab` import, a restore that installs from a unit, the data move's record — writes the app's record HERE with
|
||||
// Deployed set, so the rule „an install of the same app deletes its off-site end record” cannot be missed by a
|
||||
// path that did not exist when it was written. Pinned by TestD72_TheInstallWritersAreListed.
|
||||
if cfg.Deployed {
|
||||
noteAppInstalled(stackDir)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// installedHooks: per stacks directory, what to do when an app's record is written as installed (SaveAppConfig).
|
||||
// Keyed by the directory, not a single global, so two managers in one process (tests) do not reach each other's box.
|
||||
var (
|
||||
installedHooksMu sync.RWMutex
|
||||
installedHooks = map[string]func(app string){}
|
||||
)
|
||||
|
||||
func registerInstalledHook(stacksDir string, fn func(app string)) {
|
||||
installedHooksMu.Lock()
|
||||
installedHooks[filepath.Clean(stacksDir)] = fn
|
||||
installedHooksMu.Unlock()
|
||||
}
|
||||
|
||||
func noteAppInstalled(stackDir string) {
|
||||
installedHooksMu.RLock()
|
||||
fn := installedHooks[filepath.Clean(filepath.Dir(stackDir))]
|
||||
installedHooksMu.RUnlock()
|
||||
if fn != nil {
|
||||
fn(filepath.Base(stackDir))
|
||||
}
|
||||
}
|
||||
|
||||
// appInstalledAgain deletes app's pending off-site end record (D72): the household uses the app again, and its old
|
||||
// off-site copies are restore sources again.
|
||||
func (m *Manager) appInstalledAgain(app string) {
|
||||
if m.settings == nil {
|
||||
return
|
||||
}
|
||||
if _, err := m.settings.CancelOffsiteEnd(app, "the app is installed again"); err != nil {
|
||||
m.logger.Printf("[WARN] [stacks] %s is installed again, and its off-site end record could not be deleted (%v) — the clean-up window skips an installed app anyway", app, err)
|
||||
}
|
||||
}
|
||||
|
||||
// IsLivingApp answers the clean-up window's question (backup.SetOffsiteEndLiving): is this app installed on the box
|
||||
// right now, being installed, or one of the box's own protected stacks? Such an app's off-site copies are never
|
||||
// ended and it can get no end record. It reads THREE places, because each alone has a hole:
|
||||
// - the protected list (config) — an infra stack has no app.yaml and reads as not deployed;
|
||||
// - the manager's own list — Deployed, Deploying, Protected;
|
||||
// - the app's record ON DISK — an installed app the manager does not list (its template left the catalog, or the
|
||||
// list is mid-rescan) is still installed.
|
||||
//
|
||||
// Pinned by TestD72_IsLivingApp.
|
||||
func (m *Manager) IsLivingApp(app string) bool {
|
||||
if app == "" || m.cfg.IsProtectedStack(app) {
|
||||
return true
|
||||
}
|
||||
if st, ok := m.GetStack(app); ok && (st.Deployed || st.Deploying || st.Protected) {
|
||||
return true
|
||||
}
|
||||
if app != filepath.Base(app) || strings.ContainsAny(app, `/\`) {
|
||||
return true // not a stack name: never „removed”
|
||||
}
|
||||
if c := LoadAppConfig(filepath.Join(m.cfg.Paths.StacksDir, app)); c != nil && c.Deployed {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// LoadAppConfigDecrypted loads app.yaml and decrypts any encrypted values.
|
||||
func LoadAppConfigDecrypted(stackDir string, encKey []byte) *AppConfig {
|
||||
cfg := LoadAppConfig(stackDir)
|
||||
|
||||
@@ -149,6 +149,8 @@ func (m *Manager) SetMigrationDeps(sett *settings.Settings, backupRunning func()
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.settings = sett
|
||||
// D72: every write of an app's record as installed deletes its off-site end record (SaveAppConfig).
|
||||
registerInstalledHook(m.cfg.Paths.StacksDir, m.appInstalledAgain)
|
||||
m.backupRunning = backupRunning
|
||||
m.sysDataPath = m.cfg.Paths.SystemDataPath
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user