From efe9fe6124b74c7de8b380908dc350b2dd48b2f8 Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Fri, 10 Jul 2020 08:30:23 -0700 Subject: [PATCH] azure: Return success when deleting non-existent object (#9981) --- cmd/api-datatypes.go | 2 +- cmd/bucket-handlers.go | 7 +++++++ cmd/gateway/azure/gateway-azure.go | 13 ++++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/api-datatypes.go b/cmd/api-datatypes.go index eb74e20f7..e663b44ab 100644 --- a/cmd/api-datatypes.go +++ b/cmd/api-datatypes.go @@ -22,7 +22,7 @@ import ( // DeletedObject objects deleted type DeletedObject struct { - DeleteMarker bool `xml:"DeleteMarker"` + DeleteMarker bool `xml:"DeleteMarker,omitempty"` DeleteMarkerVersionID string `xml:"DeleteMarkerVersionId,omitempty"` ObjectName string `xml:"Key,omitempty"` VersionID string `xml:"VersionId,omitempty"` diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index 472a056b1..70cb26e71 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -377,6 +377,13 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter, return } + // Before proceeding validate if bucket exists. + _, err := objectAPI.GetBucketInfo(ctx, bucket) + if err != nil { + writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) + return + } + deleteObjectsFn := objectAPI.DeleteObjects if api.CacheAPI() != nil { deleteObjectsFn = api.CacheAPI().DeleteObjects diff --git a/cmd/gateway/azure/gateway-azure.go b/cmd/gateway/azure/gateway-azure.go index d5534a753..d1e594518 100644 --- a/cmd/gateway/azure/gateway-azure.go +++ b/cmd/gateway/azure/gateway-azure.go @@ -462,6 +462,8 @@ func azureToObjectError(err error, params ...string) error { func azureCodesToObjectError(err error, serviceCode string, statusCode int, bucket string, object string) error { switch serviceCode { + case "ContainerNotFound": + err = minio.BucketNotFound{Bucket: bucket} case "ContainerAlreadyExists": err = minio.BucketExists{Bucket: bucket} case "InvalidResourceName": @@ -970,7 +972,10 @@ func (a *azureObjects) DeleteObject(ctx context.Context, bucket, object string, blob := a.client.NewContainerURL(bucket).NewBlobURL(object) _, err := blob.Delete(ctx, azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{}) if err != nil { - return minio.ObjectInfo{}, azureToObjectError(err, bucket, object) + err = azureToObjectError(err, bucket, object) + if !errors.Is(err, minio.ObjectNotFound{Bucket: bucket, Object: object}) { + return minio.ObjectInfo{}, err + } } return minio.ObjectInfo{ Bucket: bucket, @@ -983,10 +988,8 @@ func (a *azureObjects) DeleteObjects(ctx context.Context, bucket string, objects dobjects := make([]minio.DeletedObject, len(objects)) for idx, object := range objects { _, errs[idx] = a.DeleteObject(ctx, bucket, object.ObjectName, opts) - if errs[idx] == nil { - dobjects[idx] = minio.DeletedObject{ - ObjectName: object.ObjectName, - } + dobjects[idx] = minio.DeletedObject{ + ObjectName: object.ObjectName, } } return dobjects, errs