SaveSnapshot 保存快照
(ctx context.Context, agentID string, snapshot types.Snapshot)
| 199 | |
| 200 | // SaveSnapshot 保存快照 |
| 201 | func (js *JSONStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error { |
| 202 | js.mu.Lock() |
| 203 | defer js.mu.Unlock() |
| 204 | |
| 205 | if err := js.ensureAgentDir(agentID); err != nil { |
| 206 | return err |
| 207 | } |
| 208 | |
| 209 | // 创建snapshots目录 |
| 210 | snapshotsDir := filepath.Join(js.agentDir(agentID), "snapshots") |
| 211 | if err := os.MkdirAll(snapshotsDir, 0755); err != nil { |
| 212 | return fmt.Errorf("create snapshots directory: %w", err) |
| 213 | } |
| 214 | |
| 215 | path := filepath.Join(snapshotsDir, snapshot.ID+".json") |
| 216 | return js.saveJSON(path, snapshot) |
| 217 | } |
| 218 | |
| 219 | // LoadSnapshot 加载快照 |
| 220 | func (js *JSONStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error) { |
nothing calls this directly
no test coverage detected