ListSnapshots 列出快照
(ctx context.Context, agentID string)
| 232 | |
| 233 | // ListSnapshots 列出快照 |
| 234 | func (js *JSONStore) ListSnapshots(ctx context.Context, agentID string) ([]types.Snapshot, error) { |
| 235 | js.mu.RLock() |
| 236 | defer js.mu.RUnlock() |
| 237 | |
| 238 | snapshotsDir := filepath.Join(js.agentDir(agentID), "snapshots") |
| 239 | entries, err := os.ReadDir(snapshotsDir) |
| 240 | if err != nil { |
| 241 | if os.IsNotExist(err) { |
| 242 | return []types.Snapshot{}, nil |
| 243 | } |
| 244 | return nil, fmt.Errorf("read snapshots directory: %w", err) |
| 245 | } |
| 246 | |
| 247 | snapshots := make([]types.Snapshot, 0, len(entries)) |
| 248 | for _, entry := range entries { |
| 249 | if entry.IsDir() || filepath.Ext(entry.Name()) != ".json" { |
| 250 | continue |
| 251 | } |
| 252 | |
| 253 | var snapshot types.Snapshot |
| 254 | path := filepath.Join(snapshotsDir, entry.Name()) |
| 255 | if err := js.loadJSON(path, &snapshot); err != nil { |
| 256 | continue // 忽略损坏的文件 |
| 257 | } |
| 258 | |
| 259 | snapshots = append(snapshots, snapshot) |
| 260 | } |
| 261 | |
| 262 | return snapshots, nil |
| 263 | } |
| 264 | |
| 265 | // SaveInfo 保存Agent元信息 |
| 266 | func (js *JSONStore) SaveInfo(ctx context.Context, agentID string, info types.AgentInfo) error { |