mirror of
https://github.com/getcompanion-ai/computer-host.git
synced 2026-04-15 06:04:38 +00:00
fix: reconcile race fix, disk regression for snapshot deletion
This commit is contained in:
parent
09d9e7c23b
commit
218cc3fecb
11 changed files with 193 additions and 123 deletions
|
|
@ -489,7 +489,10 @@ func (d *Daemon) DeleteSnapshotByID(ctx context.Context, snapshotID contracthost
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
snapshotDir := filepath.Dir(snap.MemFilePath)
|
||||
snapshotDir, ok := snapshotDirectory(*snap)
|
||||
if !ok {
|
||||
return fmt.Errorf("snapshot %q has no local artifact directory", snapshotID)
|
||||
}
|
||||
if err := os.RemoveAll(snapshotDir); err != nil {
|
||||
return fmt.Errorf("remove snapshot dir %q: %w", snapshotDir, err)
|
||||
}
|
||||
|
|
@ -520,6 +523,25 @@ func snapshotArtifactsToContract(artifacts []model.SnapshotArtifactRecord) []con
|
|||
return converted
|
||||
}
|
||||
|
||||
func snapshotDirectory(snapshot model.SnapshotRecord) (string, bool) {
|
||||
for _, artifact := range snapshot.Artifacts {
|
||||
if path := strings.TrimSpace(artifact.LocalPath); path != "" {
|
||||
return filepath.Dir(path), true
|
||||
}
|
||||
}
|
||||
for _, diskPath := range snapshot.DiskPaths {
|
||||
if path := strings.TrimSpace(diskPath); path != "" {
|
||||
return filepath.Dir(path), true
|
||||
}
|
||||
}
|
||||
for _, legacyPath := range []string{snapshot.MemFilePath, snapshot.StateFilePath} {
|
||||
if path := strings.TrimSpace(legacyPath); path != "" {
|
||||
return filepath.Dir(path), true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func orderedRestoredUserDiskArtifacts(artifacts map[string]restoredSnapshotArtifact) []restoredSnapshotArtifact {
|
||||
ordered := make([]restoredSnapshotArtifact, 0, len(artifacts))
|
||||
for name, artifact := range artifacts {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue