| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "log/slog" |
| 6 | |
| 7 | "reasonix/internal/agent" |
| 8 | "reasonix/internal/botruntime" |
| 9 | ) |
| 10 | |
| 11 | func (a *App) deleteRecoveryCopy(path string) error { |
| 12 | dir := a.activeSessionDir() |
| 13 | sessionPath, _, err := validateSessionPath(dir, path) |
| 14 | if err != nil { |
| 15 | var foundErr error |
| 16 | if dir, sessionPath, foundErr = a.sessionDirForPath(path); foundErr != nil { |
| 17 | return err |
| 18 | } |
| 19 | } |
| 20 | if err := func() error { |
| 21 | defer a.lockRuntimeMutation("delete-recovery-copy")() |
| 22 | a.sessionRemovalMu.Lock() |
| 23 | defer a.sessionRemovalMu.Unlock() |
| 24 | // Read-only tabs may not own a lease, so keep this check in addition to |
| 25 | // the cross-process guards acquired by the agent helper. |
| 26 | if a.sessionOpenInAnyTab(sessionPath) { |
| 27 | return errSessionBusyElsewhere |
| 28 | } |
| 29 | if err := agent.TrashCoveredRecoveryBranch(sessionPath, dir); err != nil { |
| 30 | switch { |
| 31 | case errors.Is(err, agent.ErrRecoveryBranchNotCovered): |
| 32 | return errRecoveryCopyNotRedundant |
| 33 | case errors.Is(err, agent.ErrSessionLeaseHeld): |
| 34 | return errSessionBusyElsewhere |
| 35 | default: |
| 36 | return err |
| 37 | } |
| 38 | } |
| 39 | return nil |
| 40 | }(); err != nil { |
| 41 | return err |
| 42 | } |
| 43 | if err := botruntime.ForgetAutoSessionMappingsForPath(sessionPath); err != nil { |
| 44 | slog.Warn("desktop: failed to clear auto bot session mapping", "err", err) |
| 45 | } |
| 46 | a.removeSessionCatalogPath(sessionPath, "recovery_copy_deleted") |
| 47 | a.emitProjectTreeChangedForSessionDirs(dir) |
| 48 | a.invalidatePromptHistoryCache() |
| 49 | return nil |
| 50 | } |
| 51 |