| 55 | } |
| 56 | |
| 57 | func (s *SessionFiles) loadIndex() error { |
| 58 | data, err := os.ReadFile(filepath.Join(s.root, "index.json")) |
| 59 | if os.IsNotExist(err) { |
| 60 | s.index = nil |
| 61 | return nil |
| 62 | } |
| 63 | if err != nil { |
| 64 | return fmt.Errorf("memory: read index.json: %w", err) |
| 65 | } |
| 66 | var doc struct { |
| 67 | Sessions []SessionRecord `json:"sessions"` |
| 68 | } |
| 69 | if err := json.Unmarshal(data, &doc); err != nil { |
| 70 | return fmt.Errorf("memory: parse index.json: %w", err) |
| 71 | } |
| 72 | s.index = doc.Sessions |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | func (s *SessionFiles) pruneMissing() { |
| 77 | kept := s.index[:0] |