always copy UserDefined metadata map (#10427)

fixes #10426
This commit is contained in:
Harshavardhana 2020-09-07 09:25:28 -07:00 committed by GitHub
parent a9aaea0d67
commit 9f60e84ce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 15 deletions

View File

@ -267,10 +267,9 @@ func (er erasureObjects) newMultipartUpload(ctx context.Context, bucket string,
fi.DataDir = mustGetUUID() fi.DataDir = mustGetUUID()
fi.ModTime = UTCNow() fi.ModTime = UTCNow()
if opts.UserDefined != nil { fi.Metadata = map[string]string{}
fi.Metadata = opts.UserDefined for k, v := range opts.UserDefined {
} else { fi.Metadata[k] = v
fi.Metadata = make(map[string]string)
} }
uploadID := mustGetUUID() uploadID := mustGetUUID()
@ -543,7 +542,10 @@ func (er erasureObjects) GetMultipartInfo(ctx context.Context, bucket, object, u
return result, err return result, err
} }
result.UserDefined = fi.Metadata result.UserDefined = map[string]string{}
for k, v := range fi.Metadata {
result.UserDefined[k] = v
}
return result, nil return result, nil
} }
@ -591,7 +593,10 @@ func (er erasureObjects) ListObjectParts(ctx context.Context, bucket, object, up
result.UploadID = uploadID result.UploadID = uploadID
result.MaxParts = maxParts result.MaxParts = maxParts
result.PartNumberMarker = partNumberMarker result.PartNumberMarker = partNumberMarker
result.UserDefined = fi.Metadata result.UserDefined = map[string]string{}
for k, v := range fi.Metadata {
result.UserDefined[k] = v
}
// For empty number of parts or maxParts as zero, return right here. // For empty number of parts or maxParts as zero, return right here.
if len(fi.Parts) == 0 || maxParts == 0 { if len(fi.Parts) == 0 || maxParts == 0 {

View File

@ -635,7 +635,10 @@ func (fs *FSObjects) CopyObject(ctx context.Context, srcBucket, srcObject, dstBu
fsMeta = fs.defaultFsJSON(srcObject) fsMeta = fs.defaultFsJSON(srcObject)
} }
fsMeta.Meta = srcInfo.UserDefined fsMeta.Meta = map[string]string{}
for k, v := range srcInfo.UserDefined {
fsMeta.Meta[k] = v
}
fsMeta.Meta["etag"] = srcInfo.ETag fsMeta.Meta["etag"] = srcInfo.ETag
if _, err = fsMeta.WriteTo(wlk); err != nil { if _, err = fsMeta.WriteTo(wlk); err != nil {
return oi, toObjectErr(err, srcBucket, srcObject) return oi, toObjectErr(err, srcBucket, srcObject)
@ -885,10 +888,10 @@ func (fs *FSObjects) getObject(ctx context.Context, bucket, object string, offse
// Create a new fs.json file, if the existing one is corrupt. Should happen very rarely. // Create a new fs.json file, if the existing one is corrupt. Should happen very rarely.
func (fs *FSObjects) createFsJSON(object, fsMetaPath string) error { func (fs *FSObjects) createFsJSON(object, fsMetaPath string) error {
fsMeta := newFSMetaV1() fsMeta := newFSMetaV1()
fsMeta.Meta = make(map[string]string) fsMeta.Meta = map[string]string{
fsMeta.Meta["etag"] = GenETag() "etag": GenETag(),
contentType := mimedb.TypeByExtension(path.Ext(object)) "content-type": mimedb.TypeByExtension(path.Ext(object)),
fsMeta.Meta["content-type"] = contentType }
wlk, werr := fs.rwPool.Create(fsMetaPath) wlk, werr := fs.rwPool.Create(fsMetaPath)
if werr == nil { if werr == nil {
_, err := fsMeta.WriteTo(wlk) _, err := fsMeta.WriteTo(wlk)
@ -901,10 +904,10 @@ func (fs *FSObjects) createFsJSON(object, fsMetaPath string) error {
// Used to return default etag values when a pre-existing object's meta data is queried. // Used to return default etag values when a pre-existing object's meta data is queried.
func (fs *FSObjects) defaultFsJSON(object string) fsMetaV1 { func (fs *FSObjects) defaultFsJSON(object string) fsMetaV1 {
fsMeta := newFSMetaV1() fsMeta := newFSMetaV1()
fsMeta.Meta = make(map[string]string) fsMeta.Meta = map[string]string{
fsMeta.Meta["etag"] = defaultEtag "etag": defaultEtag,
contentType := mimedb.TypeByExtension(path.Ext(object)) "content-type": mimedb.TypeByExtension(path.Ext(object)),
fsMeta.Meta["content-type"] = contentType }
return fsMeta return fsMeta
} }