WipeCredentialsFile removes ~/.pad/credentials.json entirely. Distinct from CredentialStore.Delete (which removes a single server's entry) — used by tests and any future "pad auth wipe" that wants a clean slate. Silently succeeds if the file is already absent. Under the exclusive lock, so it cannot
()
| 582 | // Under the exclusive lock, so it cannot land in the middle of a save |
| 583 | // (BUG-3649). Never call it from an UpdateStore callback. |
| 584 | func WipeCredentialsFile() error { |
| 585 | // No ~/.pad, nothing to wipe: answered without creating it, which on a |
| 586 | // read-only home would fail where the wipe used to succeed. |
| 587 | if path, err := credentialsPath(); err == nil { |
| 588 | if _, err := os.Stat(filepath.Dir(path)); errors.Is(err, fs.ErrNotExist) { |
| 589 | return nil |
| 590 | } |
| 591 | } |
| 592 | return withCredentialsLock(true, func(path string, _ bool) error { |
| 593 | if err := os.Remove(path); err != nil && !os.IsNotExist(err) { |
| 594 | return fmt.Errorf("delete credentials: %w", err) |
| 595 | } |
| 596 | return nil |
| 597 | }) |
| 598 | } |
| 599 | |
| 600 | // normalizeServerURL canonicalizes a server URL for use as a credential |
| 601 | // key. Trailing slash and surrounding whitespace are stripped; nothing |