* Detect whether writing `fresh` would lose auth/onboarding state that the * in-memory cache still has. This happens when `getConfig` hits a corrupted * or truncated file mid-write (from another process or a non-atomic fallback) * and returns DEFAULT_GLOBAL_CONFIG. Writing that back would permane
(fresh: {
oauthAccount?: unknown
hasCompletedOnboarding?: boolean
})
| 781 | * wipe auth. See GH #3117. |
| 782 | */ |
| 783 | function wouldLoseAuthState(fresh: { |
| 784 | oauthAccount?: unknown |
| 785 | hasCompletedOnboarding?: boolean |
| 786 | }): boolean { |
| 787 | const cached = globalConfigCache.config |
| 788 | if (!cached) return false |
| 789 | const lostOauth = |
| 790 | cached.oauthAccount !== undefined && fresh.oauthAccount === undefined |
| 791 | const lostOnboarding = |
| 792 | cached.hasCompletedOnboarding === true && |
| 793 | fresh.hasCompletedOnboarding !== true |
| 794 | return lostOauth || lostOnboarding |
| 795 | } |
| 796 | |
| 797 | export function saveGlobalConfig( |
| 798 | updater: (currentConfig: GlobalConfig) => GlobalConfig, |
no outgoing calls
no test coverage detected