From 380a7c720bbf72daa212ebb72c317939c615e135 Mon Sep 17 00:00:00 2001 From: Jiaqiang Huang <96465211+River2000i@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:16:01 +0800 Subject: [PATCH] ignore error by backend type --- dm/pkg/storage/utils.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dm/pkg/storage/utils.go b/dm/pkg/storage/utils.go index 1a260cbd748..0232dcfbfec 100644 --- a/dm/pkg/storage/utils.go +++ b/dm/pkg/storage/utils.go @@ -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 } }