diff --git a/cmd/erasure-sets.go b/cmd/erasure-sets.go index a5d58aac3..02cd31ddd 100644 --- a/cmd/erasure-sets.go +++ b/cmd/erasure-sets.go @@ -791,7 +791,12 @@ func (s *erasureSets) CopyObject(ctx context.Context, srcBucket, srcObject, dstB // Check if this request is only metadata update. if srcSet == dstSet && srcInfo.metadataOnly { - return srcSet.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) + if dstOpts.VersionID != "" && srcOpts.VersionID == dstOpts.VersionID { + return srcSet.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) + } + if !dstOpts.Versioned && srcOpts.VersionID == "" { + return srcSet.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) + } } putOpts := ObjectOptions{ @@ -800,6 +805,7 @@ func (s *erasureSets) CopyObject(ctx context.Context, srcBucket, srcObject, dstB Versioned: dstOpts.Versioned, VersionID: dstOpts.VersionID, } + return dstSet.putObject(ctx, dstBucket, dstObject, srcInfo.PutObjReader, putOpts) } diff --git a/cmd/erasure-zones.go b/cmd/erasure-zones.go index ba01458dc..bc16aba0b 100644 --- a/cmd/erasure-zones.go +++ b/cmd/erasure-zones.go @@ -595,6 +595,15 @@ func (z *erasureZones) CopyObject(ctx context.Context, srcBucket, srcObject, dst return objInfo, err } + if cpSrcDstSame && srcInfo.metadataOnly && srcOpts.VersionID == dstOpts.VersionID { + if dstOpts.VersionID != "" && srcOpts.VersionID == dstOpts.VersionID { + return z.zones[zoneIdx].CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) + } + if !dstOpts.Versioned && srcOpts.VersionID == "" { + return z.zones[zoneIdx].CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) + } + } + putOpts := ObjectOptions{ ServerSideEncryption: dstOpts.ServerSideEncryption, UserDefined: srcInfo.UserDefined, @@ -602,10 +611,6 @@ func (z *erasureZones) CopyObject(ctx context.Context, srcBucket, srcObject, dst VersionID: dstOpts.VersionID, } - if cpSrcDstSame && srcInfo.metadataOnly { - return z.zones[zoneIdx].CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) - } - return z.zones[zoneIdx].PutObject(ctx, dstBucket, dstObject, srcInfo.PutObjReader, putOpts) } diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index e6c5e6b85..069c76cc7 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -2692,7 +2692,9 @@ func (api objectAPIHandlers) PutObjectLegalHoldHandler(w http.ResponseWriter, r objInfo.metadataOnly = true if _, err = objectAPI.CopyObject(ctx, bucket, object, bucket, object, objInfo, ObjectOptions{ VersionID: opts.VersionID, - }, ObjectOptions{}); err != nil { + }, ObjectOptions{ + VersionID: opts.VersionID, + }); err != nil { writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) return } @@ -2850,7 +2852,9 @@ func (api objectAPIHandlers) PutObjectRetentionHandler(w http.ResponseWriter, r objInfo.metadataOnly = true // Perform only metadata updates. if _, err = objectAPI.CopyObject(ctx, bucket, object, bucket, object, objInfo, ObjectOptions{ VersionID: opts.VersionID, - }, ObjectOptions{}); err != nil { + }, ObjectOptions{ + VersionID: opts.VersionID, + }); err != nil { writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) return }