diff --git a/api.go b/api.go index 387c55a..28ebdca 100644 --- a/api.go +++ b/api.go @@ -155,6 +155,14 @@ func (a *Agate) SaveSnapshot(ctx context.Context, name string, parentID string) } } + defer func() { + if a.options.OpenFunc != nil { + if err := a.options.OpenFunc(a.options.BlobStore.GetActiveDir()); err != nil { + fmt.Printf("Failed to open resources after snapshot: %v\n", err) + } + } + }() + // If parentID is not provided, use the current snapshot ID if parentID == "" { parentID = a.currentSnapshotID @@ -176,13 +184,6 @@ func (a *Agate) SaveSnapshot(ctx context.Context, name string, parentID string) return "", fmt.Errorf("failed to save current snapshot ID: %w", err) } - // Call OpenFunc if provided - if a.options.OpenFunc != nil { - if err := a.options.OpenFunc(a.options.BlobStore.GetActiveDir()); err != nil { - return "", fmt.Errorf("failed to open resources after snapshot: %w", err) - } - } - return snapshot.ID, nil } @@ -227,6 +228,14 @@ func (a *Agate) RestoreSnapshotToDir(ctx context.Context, snapshotID string, dir } } + defer func() { + if a.options.OpenFunc != nil { + if err := a.options.OpenFunc(dir); err != nil { + fmt.Printf("Failed to open resources after snapshot: %v\n", err) + } + } + }() + // Extract the snapshot if err := a.manager.ExtractSnapshot(ctx, snapshotID, dir); err != nil { return fmt.Errorf("failed to extract snapshot: %w", err) @@ -242,13 +251,6 @@ func (a *Agate) RestoreSnapshotToDir(ctx context.Context, snapshotID string, dir } } - // Call OpenFunc if provided - if a.options.OpenFunc != nil { - if err := a.options.OpenFunc(dir); err != nil { - return fmt.Errorf("failed to open resources after restore: %w", err) - } - } - return nil }