| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "slices" |
| 5 | |
| 6 | "reasonix/desktop/internal/legacycleanup" |
| 7 | "reasonix/desktop/internal/workspacestate" |
| 8 | "reasonix/internal/session" |
| 9 | ) |
| 10 | |
| 11 | func classifyLegacyCleanupPersistentOwner(state workspacestate.State, ref session.SessionRef, frozen legacycleanup.Candidate) (legacyCleanupDecision, bool) { |
| 12 | protected := func(reason string) (legacyCleanupDecision, bool) { |
| 13 | return legacyCleanupDecision{"protected", reason, session.SessionInfo{}, session.Snapshot{}}, true |
| 14 | } |
| 15 | for _, recovery := range state.RecoveryEntries { |
| 16 | if recovery.SessionID == ref.SessionID { |
| 17 | return protected("recovery_owner") |
| 18 | } |
| 19 | for _, source := range frozen.Sources { |
| 20 | if recovery.Path != "" && sameDesktopPath(recovery.Path, source.Path) { |
| 21 | return protected("recovery_owner") |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | for _, operation := range state.PendingOperations { |
| 26 | // Committed operations are durable receipts, not active owners. |
| 27 | if operation.ID == frozen.OperationID || operation.Phase == "committed" { |
| 28 | continue |
| 29 | } |
| 30 | mapped := operation.Mapping != nil && operation.Mapping.SessionID == ref.SessionID |
| 31 | if slices.Contains(operation.SessionIDs, ref.SessionID) || mapped { |
| 32 | return protected("pending_operation") |
| 33 | } |
| 34 | } |
| 35 | return legacyCleanupDecision{}, false |
| 36 | } |
| 37 |