From ab966410d2a180344d0275354aeac5c599bb7c66 Mon Sep 17 00:00:00 2001 From: "ruitao.liu" Date: Thu, 12 Nov 2020 16:44:16 +0800 Subject: [PATCH] return NoSuchBucket instead of InternalError delete non-existed bucket. --- weed/s3api/s3api_bucket_handlers.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/weed/s3api/s3api_bucket_handlers.go b/weed/s3api/s3api_bucket_handlers.go index 744f22617..1e6d710be 100644 --- a/weed/s3api/s3api_bucket_handlers.go +++ b/weed/s3api/s3api_bucket_handlers.go @@ -120,16 +120,19 @@ func (s3a *S3ApiServer) DeleteBucketHandler(w http.ResponseWriter, r *http.Reque bucket, _ := getBucketAndObject(r) - if entry, err := s3a.get(s3a.option.BucketsPath, bucket); entry != nil && err == nil { - if id, ok := entry.Extended[xhttp.AmzIdentityId]; ok { - if string(id) != r.Header.Get(xhttp.AmzIdentityId) { - writeErrorResponse(w, s3err.ErrAccessDenied, r.URL) - return - } + entry, err := s3a.get(s3a.option.BucketsPath, bucket) + if entry == nil || err == filer_pb.ErrNotFound { + writeErrorResponse(w, s3err.ErrNoSuchBucket, r.URL) + return + } + if id, ok := entry.Extended[xhttp.AmzIdentityId]; ok { + if string(id) != r.Header.Get(xhttp.AmzIdentityId) { + writeErrorResponse(w, s3err.ErrAccessDenied, r.URL) + return } } - err := s3a.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { + err = s3a.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { // delete collection deleteCollectionRequest := &filer_pb.DeleteCollectionRequest{