mirror of https://github.com/databricks/cli.git
Delete sync snapshots file when destroying a bundle (#323)
## Changes This PR changes the files.Delete() mutator to delete the sync snapshots file on destroy. This ensures that files will be uploaded when the bundle is uploaded again. ## Tests - [x] Manual test: Ran `bricks bundle destroy`, observed that the sync snapshots file was deleted.
This commit is contained in:
parent
42d29f92c9
commit
946906221d
|
@ -49,6 +49,16 @@ func (m *delete) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Clean up sync snapshot file
|
||||
sync, err := getSync(ctx, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = sync.DestroySnapshot(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Println("Successfully deleted files!")
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package files
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/databricks/bricks/bundle"
|
||||
"github.com/databricks/bricks/libs/sync"
|
||||
)
|
||||
|
||||
func getSync(ctx context.Context, b *bundle.Bundle) (*sync.Sync, error) {
|
||||
cacheDir, err := b.CacheDir()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
||||
}
|
||||
|
||||
opts := sync.SyncOptions{
|
||||
LocalPath: b.Config.Path,
|
||||
RemotePath: b.Config.Workspace.FilePath.Workspace,
|
||||
Full: false,
|
||||
|
||||
SnapshotBasePath: cacheDir,
|
||||
WorkspaceClient: b.WorkspaceClient(),
|
||||
}
|
||||
return sync.New(ctx, opts)
|
||||
}
|
|
@ -2,10 +2,8 @@ package files
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/databricks/bricks/bundle"
|
||||
sync "github.com/databricks/bricks/libs/sync"
|
||||
)
|
||||
|
||||
type upload struct{}
|
||||
|
@ -15,21 +13,7 @@ func (m *upload) Name() string {
|
|||
}
|
||||
|
||||
func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
|
||||
cacheDir, err := b.CacheDir()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
||||
}
|
||||
|
||||
opts := sync.SyncOptions{
|
||||
LocalPath: b.Config.Path,
|
||||
RemotePath: b.Config.Workspace.FilePath.Workspace,
|
||||
Full: false,
|
||||
|
||||
SnapshotBasePath: cacheDir,
|
||||
WorkspaceClient: b.WorkspaceClient(),
|
||||
}
|
||||
|
||||
sync, err := sync.New(ctx, opts)
|
||||
sync, err := getSync(ctx, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -126,6 +126,14 @@ func (s *Snapshot) Save(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Snapshot) Destroy(ctx context.Context) error {
|
||||
err := os.Remove(s.SnapshotPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to destroy sync snapshot file: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadOrNewSnapshot(ctx context.Context, opts *SyncOptions) (*Snapshot, error) {
|
||||
snapshot, err := newSnapshot(ctx, opts)
|
||||
if err != nil {
|
||||
|
|
|
@ -160,6 +160,10 @@ func (s *Sync) RunOnce(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Sync) DestroySnapshot(ctx context.Context) error {
|
||||
return s.snapshot.Destroy(ctx)
|
||||
}
|
||||
|
||||
func (s *Sync) RunContinuous(ctx context.Context) error {
|
||||
ticker := time.NewTicker(s.PollInterval)
|
||||
defer ticker.Stop()
|
||||
|
|
Loading…
Reference in New Issue