MCPcopy Create free account
hub / github.com/astercloud/aster / ListSnapshots

Method ListSnapshots

pkg/store/json.go:234–263  ·  view source on GitHub ↗

ListSnapshots 列出快照

(ctx context.Context, agentID string)

Source from the content-addressed store, hash-verified

232
233// ListSnapshots 列出快照
234func (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元信息
266func (js *JSONStore) SaveInfo(ctx context.Context, agentID string, info types.AgentInfo) error {

Callers

nothing calls this directly

Calls 4

agentDirMethod · 0.95
loadJSONMethod · 0.95
NameMethod · 0.65
JoinMethod · 0.45

Tested by

no test coverage detected