Review fix 2: a take-back or an install during the clean-up window keeps the copies (D72)

The due end records and the candidates were read once, before the hub was
asked, and never again before the forget. A „Mégis megtartom” or an install
while the hub answered still deleted the copies.

The window now reads the records again immediately before the forget and takes
out every id whose record is gone, changed or no longer due. From that look
until the forget has ended, a take-back is answered „not marked, or already
deleted”, never „kept”. Not covered: an install during the forget itself.

Tests seen red on f628cb5, then green; mutations in felhom.eu
documentation/audits/build-release-4-2026-11-15/A/redproof-review-2.txt.

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-15 14:27:09 +01:00
1 parent f628cb5082
commit 3928c3db28
5 files changed
+221 -1

No files matched your search

+65 -1
View File
@@ -245,11 +245,75 @@ func (m *Manager) StartOffsiteEnd(app string) (rec settings.OffsiteEnd, created
return rec, true, nil
}
// KeepOffsiteCopies is „keep it after all”: it deletes the end record. Returns whether there was one.
// KeepOffsiteCopies is „keep it after all”: it deletes the end record. Returns whether there was one TO KEEP: false
// also while a clean-up window is removing this app's copies right now (its last look at the records is behind it) —
// the page then says „not marked, or already deleted”, never „kept” over copies that are going.
func (m *Manager) KeepOffsiteCopies(app string) (bool, error) {
m.offsiteEndMu.Lock()
defer m.offsiteEndMu.Unlock()
if m.offsiteEndRemoving[app] {
m.logger.Printf("[WARN] [offbox] keep-after-all for %s came while the clean-up window is removing its off-site copies — too late, not kept", app)
return false, nil
}
return m.settings.CancelOffsiteEnd(app, "the household keeps the copies")
}
// lastLookAtEnded reads the end records AGAIN, immediately before the forget, and keeps of the agreed ids only those
// whose EVERY app still has the SAME record (app and removed_at), still due, still not installed. It returns the ids
// and the claims that are left, and marks those apps as „being removed” until endedRemovalOver. One lock with
// KeepOffsiteCopies, so a take-back is either before this look (its record is gone: its ids are taken out here) or
// after it (answered „too late”).
//
// NOT covered, said plainly: an INSTALL of the app during the forget itself. It deletes the record through settings
// (stacks.SaveAppConfig), restic is already removing, and the copies go. The window is one `forget … --prune`.
func (m *Manager) lastLookAtEnded(snaps []guardSnap, claims []OffsiteEndedClaim, endedIDs []string) ([]string, []OffsiteEndedClaim) {
m.offsiteEndMu.Lock()
defer m.offsiteEndMu.Unlock()
m.offsiteEndRemoving = nil
if len(endedIDs) == 0 {
return nil, claims
}
due := dueOffsiteEnds(m.settings.GetOffsiteEnds(), m.now(), m.offsiteEndLiving)
claimed := make(map[string]string, len(claims))
for _, c := range claims {
claimed[c.App] = c.RemovedAt
}
for app, e := range due {
if at, ok := claimed[app]; !ok || at != e.RemovedAt {
delete(due, app) // a record this window did not claim, or one written anew since: not this window's
}
}
var left []OffsiteEndedClaim
for _, c := range claims {
if _, ok := due[c.App]; ok {
left = append(left, c)
} else {
m.logger.Printf("[WARN] [offbox] ended app %s: its end record changed while the window was being prepared (taken back, installed again, or written anew) — nothing of it is removed", c.App)
}
}
_, candidate := endedCandidates(snaps, due)
var ids []string
for _, id := range endedIDs {
if candidate[id] {
ids = append(ids, id)
}
}
if len(ids) > 0 {
m.offsiteEndRemoving = map[string]bool{}
for app := range due {
m.offsiteEndRemoving[app] = true
}
}
return ids, left
}
// endedRemovalOver ends the „being removed” mark (the forget has ended, whatever its result).
func (m *Manager) endedRemovalOver() {
m.offsiteEndMu.Lock()
m.offsiteEndRemoving = nil
m.offsiteEndMu.Unlock()
}
// PendingOffsiteEnds and OffsiteEndsHistory are what the Backups page shows.
func (m *Manager) PendingOffsiteEnds() []settings.OffsiteEnd { return m.settings.GetOffsiteEnds() }
func (m *Manager) OffsiteEndsHistory() []settings.OffsiteEndDone {