persistLocked writes the current sessions to disk (mode 0600). The caller must hold s.mu. Best-effort: a write failure only means sessions won't survive the next restart, so it is logged but not fatal.
()
| 80 | // hold s.mu. Best-effort: a write failure only means sessions won't survive the |
| 81 | // next restart, so it is logged but not fatal. |
| 82 | func (s *sessionStore) persistLocked() { |
| 83 | if s.path == "" { |
| 84 | return |
| 85 | } |
| 86 | data, err := json.Marshal(s.sessions) |
| 87 | if err != nil { |
| 88 | return |
| 89 | } |
| 90 | if err := os.WriteFile(s.path, data, 0o600); err != nil { |
| 91 | log.Printf("sessions: could not persist to %q: %v", s.path, err) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func (s *sessionStore) create() (string, time.Time, error) { |
| 96 | buf := make([]byte, 32) |