mirror of https://github.com/databricks/cli.git
[DECO-200] Ignore RESOURCE_DOES_NOT_EXIST errors on file deletion during sync (#85)
tested manually
This commit is contained in:
parent
1329bc05d4
commit
0601e114fd
|
@ -13,6 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/databricks/bricks/project"
|
"github.com/databricks/bricks/project"
|
||||||
|
"github.com/databricks/databricks-sdk-go/databricks/apierr"
|
||||||
"github.com/databricks/databricks-sdk-go/databricks/client"
|
"github.com/databricks/databricks-sdk-go/databricks/client"
|
||||||
"github.com/databricks/databricks-sdk-go/service/workspace"
|
"github.com/databricks/databricks-sdk-go/service/workspace"
|
||||||
"github.com/databricks/databricks-sdk-go/workspaces"
|
"github.com/databricks/databricks-sdk-go/workspaces"
|
||||||
|
@ -44,6 +45,23 @@ func putFile(ctx context.Context, path string, content io.Reader) error {
|
||||||
return apiClient.Post(ctx, apiPath, content, nil)
|
return apiClient.Post(ctx, apiPath, content, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteFile(ctx context.Context, path string, wsc *workspaces.WorkspacesClient) error {
|
||||||
|
err := wsc.Workspace.Delete(ctx,
|
||||||
|
workspace.Delete{
|
||||||
|
Path: path,
|
||||||
|
Recursive: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
// We explictly ignore RESOURCE_DOES_NOT_EXIST errors for deletion of files
|
||||||
|
// This makes deletion operation idempotent and allows us to not crash syncing on
|
||||||
|
// edge cases for eg: this api fails to delete notebooks, and returns a
|
||||||
|
// RESOURCE_DOES_NOT_EXIST error instead
|
||||||
|
if val, ok := err.(apierr.APIError); ok && val.ErrorCode == "RESOURCE_DOES_NOT_EXIST" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func getRemoteSyncCallback(ctx context.Context, root, remoteDir string, wsc *workspaces.WorkspacesClient) func(localDiff diff) error {
|
func getRemoteSyncCallback(ctx context.Context, root, remoteDir string, wsc *workspaces.WorkspacesClient) func(localDiff diff) error {
|
||||||
return func(d diff) error {
|
return func(d diff) error {
|
||||||
|
|
||||||
|
@ -61,12 +79,7 @@ func getRemoteSyncCallback(ctx context.Context, root, remoteDir string, wsc *wor
|
||||||
// is evaluated
|
// is evaluated
|
||||||
localFileName := fileName
|
localFileName := fileName
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
err := wsc.Workspace.Delete(ctx,
|
err := deleteFile(ctx, path.Join(remoteDir, localFileName), wsc)
|
||||||
workspace.Delete{
|
|
||||||
Path: path.Join(remoteDir, localFileName),
|
|
||||||
Recursive: true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue