From 491f7636f8a6d24dcb65f1b23132101b2f565b4b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 3 Sep 2021 17:38:39 -0700 Subject: [PATCH] s3: CopyObject return http Status 400 Bad Request for non-existing source fix https://github.com/chrislusf/seaweedfs/issues/2306 --- weed/s3api/s3api_object_copy_handlers.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/weed/s3api/s3api_object_copy_handlers.go b/weed/s3api/s3api_object_copy_handlers.go index 60dd54152..86dec2b45 100644 --- a/weed/s3api/s3api_object_copy_handlers.go +++ b/weed/s3api/s3api_object_copy_handlers.go @@ -33,11 +33,13 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request entry, err := s3a.getEntry(dir, name) if err != nil { s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r) + return } entry.Extended = weed_server.SaveAmzMetaData(r, entry.Extended, isReplace(r)) err = s3a.touch(dir, name, entry) if err != nil { s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r) + return } writeSuccessResponseXML(w, CopyObjectResult{ ETag: fmt.Sprintf("%x", entry.Attributes.Md5), @@ -51,6 +53,13 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r) return } + srcPath := util.FullPath(fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, srcObject, srcObject)) + dir, name := srcPath.DirAndName() + _, err = s3a.getEntry(dir, name) + if err != nil { + s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r) + return + } if srcBucket == dstBucket && srcObject == dstObject { s3err.WriteErrorResponse(w, s3err.ErrInvalidCopyDest, r)