change updateVersion to only update keys, no deletes (#12032)

there are situations where metadata can have keys
with empty values, preserve existing behavior
This commit is contained in:
Harshavardhana 2021-04-10 09:13:12 -07:00 committed by GitHub
parent d50193d30f
commit 641150f2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 13 deletions

View File

@ -623,7 +623,9 @@ func putRestoreOpts(bucket, object string, rreq *RestoreObjectRequest, objInfo O
} }
meta[v.Name] = v.Value meta[v.Name] = v.Value
} }
meta[xhttp.AmzObjectTagging] = rreq.OutputLocation.S3.Tagging.String() if tags := rreq.OutputLocation.S3.Tagging.String(); tags != "" {
meta[xhttp.AmzObjectTagging] = tags
}
if rreq.OutputLocation.S3.Encryption.EncryptionType != "" { if rreq.OutputLocation.S3.Encryption.EncryptionType != "" {
meta[xhttp.AmzServerSideEncryption] = xhttp.AmzEncryptionAES meta[xhttp.AmzServerSideEncryption] = xhttp.AmzEncryptionAES
} }
@ -636,7 +638,9 @@ func putRestoreOpts(bucket, object string, rreq *RestoreObjectRequest, objInfo O
for k, v := range objInfo.UserDefined { for k, v := range objInfo.UserDefined {
meta[k] = v meta[k] = v
} }
if len(objInfo.UserTags) != 0 {
meta[xhttp.AmzObjectTagging] = objInfo.UserTags meta[xhttp.AmzObjectTagging] = objInfo.UserTags
}
return ObjectOptions{ return ObjectOptions{
Versioned: globalBucketVersioningSys.Enabled(bucket), Versioned: globalBucketVersioningSys.Enabled(bucket),

View File

@ -138,7 +138,10 @@ func (fi FileInfo) ToObjectInfo(bucket, object string) ObjectInfo {
objInfo.ETag = extractETag(fi.Metadata) objInfo.ETag = extractETag(fi.Metadata)
// Add user tags to the object info // Add user tags to the object info
objInfo.UserTags = fi.Metadata[xhttp.AmzObjectTagging] tags := fi.Metadata[xhttp.AmzObjectTagging]
if len(tags) != 0 {
objInfo.UserTags = tags
}
// Add replication status to the object info // Add replication status to the object info
objInfo.ReplicationStatus = replication.StatusType(fi.Metadata[xhttp.AmzBucketReplicationStatus]) objInfo.ReplicationStatus = replication.StatusType(fi.Metadata[xhttp.AmzBucketReplicationStatus])

View File

@ -739,19 +739,11 @@ func (z *xlMetaV2) UpdateObjectVersion(fi FileInfo) error {
if version.ObjectV2.VersionID == uv { if version.ObjectV2.VersionID == uv {
for k, v := range fi.Metadata { for k, v := range fi.Metadata {
if strings.HasPrefix(strings.ToLower(k), ReservedMetadataPrefixLower) { if strings.HasPrefix(strings.ToLower(k), ReservedMetadataPrefixLower) {
if v == "" {
delete(z.Versions[i].ObjectV2.MetaSys, k)
} else {
z.Versions[i].ObjectV2.MetaSys[k] = []byte(v) z.Versions[i].ObjectV2.MetaSys[k] = []byte(v)
}
} else {
if v == "" {
delete(z.Versions[i].ObjectV2.MetaUser, k)
} else { } else {
z.Versions[i].ObjectV2.MetaUser[k] = v z.Versions[i].ObjectV2.MetaUser[k] = v
} }
} }
}
if !fi.ModTime.IsZero() { if !fi.ModTime.IsZero() {
z.Versions[i].ObjectV2.ModTime = fi.ModTime.UnixNano() z.Versions[i].ObjectV2.ModTime = fi.ModTime.UnixNano()
} }