package tui import ( "context" "sync" ) // operationCommitGuard arbitrates cancellation against the first live mutation. // Package-manager commits must drain; killing them can leave the package database // inconsistent. File transactions similarly own their commit/rollback outcome. type operationCommitGuard struct { mu sync.Mutex ctx context.Context committed bool cancelled bool } func (g *operationCommitGuard) begin() error { g.mu.Lock() defer g.mu.Unlock() if err := g.ctx.Err(); err != nil { return err } if g.cancelled { return context.Canceled } g.committed = true return nil } func (g *operationCommitGuard) cancel(cancel func()) bool { if g == nil { if cancel != nil { cancel() } return true } g.mu.Lock() defer g.mu.Unlock() if g.committed { return false } g.cancelled = true if cancel != nil { cancel() } return true }