Refactor OpenFunc call to use deferred execution
This commit is contained in:
parent
0a9285c05e
commit
3489703ba7
30
api.go
30
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user