fix: generate new version when replacing metadata in CopyObject (#9871)

master
Harshavardhana 4 years ago committed by GitHub
parent fa13fe2184
commit b912c8f035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      cmd/erasure-sets.go
  2. 13
      cmd/erasure-zones.go
  3. 8
      cmd/object-handlers.go

@ -791,7 +791,12 @@ func (s *erasureSets) CopyObject(ctx context.Context, srcBucket, srcObject, dstB
// Check if this request is only metadata update. // Check if this request is only metadata update.
if srcSet == dstSet && srcInfo.metadataOnly { 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{ putOpts := ObjectOptions{
@ -800,6 +805,7 @@ func (s *erasureSets) CopyObject(ctx context.Context, srcBucket, srcObject, dstB
Versioned: dstOpts.Versioned, Versioned: dstOpts.Versioned,
VersionID: dstOpts.VersionID, VersionID: dstOpts.VersionID,
} }
return dstSet.putObject(ctx, dstBucket, dstObject, srcInfo.PutObjReader, putOpts) return dstSet.putObject(ctx, dstBucket, dstObject, srcInfo.PutObjReader, putOpts)
} }

@ -595,6 +595,15 @@ func (z *erasureZones) CopyObject(ctx context.Context, srcBucket, srcObject, dst
return objInfo, err 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{ putOpts := ObjectOptions{
ServerSideEncryption: dstOpts.ServerSideEncryption, ServerSideEncryption: dstOpts.ServerSideEncryption,
UserDefined: srcInfo.UserDefined, UserDefined: srcInfo.UserDefined,
@ -602,10 +611,6 @@ func (z *erasureZones) CopyObject(ctx context.Context, srcBucket, srcObject, dst
VersionID: dstOpts.VersionID, 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) return z.zones[zoneIdx].PutObject(ctx, dstBucket, dstObject, srcInfo.PutObjReader, putOpts)
} }

@ -2692,7 +2692,9 @@ func (api objectAPIHandlers) PutObjectLegalHoldHandler(w http.ResponseWriter, r
objInfo.metadataOnly = true objInfo.metadataOnly = true
if _, err = objectAPI.CopyObject(ctx, bucket, object, bucket, object, objInfo, ObjectOptions{ if _, err = objectAPI.CopyObject(ctx, bucket, object, bucket, object, objInfo, ObjectOptions{
VersionID: opts.VersionID, VersionID: opts.VersionID,
}, ObjectOptions{}); err != nil { }, ObjectOptions{
VersionID: opts.VersionID,
}); err != nil {
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
return return
} }
@ -2850,7 +2852,9 @@ func (api objectAPIHandlers) PutObjectRetentionHandler(w http.ResponseWriter, r
objInfo.metadataOnly = true // Perform only metadata updates. objInfo.metadataOnly = true // Perform only metadata updates.
if _, err = objectAPI.CopyObject(ctx, bucket, object, bucket, object, objInfo, ObjectOptions{ if _, err = objectAPI.CopyObject(ctx, bucket, object, bucket, object, objInfo, ObjectOptions{
VersionID: opts.VersionID, VersionID: opts.VersionID,
}, ObjectOptions{}); err != nil { }, ObjectOptions{
VersionID: opts.VersionID,
}); err != nil {
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
return return
} }

Loading…
Cancel
Save