From 08387325c4ba09bb4fe2ac9d0dfa0224a8c2c9f8 Mon Sep 17 00:00:00 2001 From: wayblink Date: Thu, 4 Jul 2024 20:56:24 +0800 Subject: [PATCH] Refine Delete API Signed-off-by: wayblink --- core/backup_context.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/backup_context.go b/core/backup_context.go index 5d7a82ec..6ea02199 100644 --- a/core/backup_context.go +++ b/core/backup_context.go @@ -392,6 +392,9 @@ func (b *BackupContext) DeleteBackup(ctx context.Context, request *backuppb.Dele getResp := b.GetBackup(b.ctx, &backuppb.GetBackupRequest{ BackupName: request.GetBackupName(), }) + // always trigger a remove to make sure it is deleted + err := b.getStorageClient().RemoveWithPrefix(ctx, b.backupBucketName, BackupDirPath(b.backupRootPath, request.GetBackupName())) + if getResp.GetCode() == backuppb.ResponseCode_Request_Object_Not_Found { resp.Code = backuppb.ResponseCode_Request_Object_Not_Found resp.Msg = getResp.GetMsg() @@ -409,11 +412,11 @@ func (b *BackupContext) DeleteBackup(ctx context.Context, request *backuppb.Dele return resp } - err := b.getStorageClient().RemoveWithPrefix(ctx, b.backupBucketName, BackupDirPath(b.backupRootPath, request.GetBackupName())) - if err != nil { log.Error("Fail to delete backup", zap.String("backupName", request.GetBackupName()), zap.Error(err)) - return nil + resp.Code = backuppb.ResponseCode_Fail + resp.Msg = getResp.GetMsg() + return resp } resp.Code = backuppb.ResponseCode_Success