Skip to content

Commit

Permalink
ignore error by backend type
Browse files Browse the repository at this point in the history
  • Loading branch information
River2000i committed Dec 20, 2024
1 parent dcece65 commit 380a7c7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions dm/pkg/storage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,29 @@ func RemoveAll(ctx context.Context, dir string, storage bstorage.ExternalStorage
return err
}
}
backend, err := bstorage.ParseBackend(dir, nil)
if err != nil {
return err
}

err = storage.WalkDir(ctx, &bstorage.WalkOption{}, func(filePath string, size int64) error {
err2 := storage.DeleteFile(ctx, filePath)
if errors.Cause(err2) == gstorage.ErrObjectNotExist || bloberror.HasCode(err2, bloberror.BlobNotFound) {
// ignore not exist error when we delete files
// ignore not exist error when we delete files and backend is gcs/azure blob storage
if backend.GetGcs() != nil && errors.Cause(err2) == gstorage.ErrObjectNotExist {
return nil
}
if backend.GetAzureBlobStorage() != nil || bloberror.HasCode(err2, bloberror.BlobNotFound) {
return nil
}
return err2
})
if err == nil {
err = storage.DeleteFile(ctx, "")
if errors.Cause(err) == gstorage.ErrObjectNotExist || bloberror.HasCode(err, bloberror.BlobNotFound) {
// ignore not exist error when we delete files
// ignore not exist error when we delete files and backend is gcs/azure blob storage
if backend.GetGcs() != nil && errors.Cause(err) == gstorage.ErrObjectNotExist {
return nil
}
if backend.GetAzureBlobStorage() != nil || bloberror.HasCode(err, bloberror.BlobNotFound) {
return nil
}
}
Expand Down

0 comments on commit 380a7c7

Please sign in to comment.