From 9f60e84ce15c2d06c089303a263e2e403eb2bf3f Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 7 Sep 2020 09:25:28 -0700 Subject: [PATCH] always copy UserDefined metadata map (#10427) fixes #10426 --- cmd/erasure-multipart.go | 17 +++++++++++------ cmd/fs-v1.go | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/cmd/erasure-multipart.go b/cmd/erasure-multipart.go index 45162fe94..18d04e19e 100644 --- a/cmd/erasure-multipart.go +++ b/cmd/erasure-multipart.go @@ -267,10 +267,9 @@ func (er erasureObjects) newMultipartUpload(ctx context.Context, bucket string, fi.DataDir = mustGetUUID() fi.ModTime = UTCNow() - if opts.UserDefined != nil { - fi.Metadata = opts.UserDefined - } else { - fi.Metadata = make(map[string]string) + fi.Metadata = map[string]string{} + for k, v := range opts.UserDefined { + fi.Metadata[k] = v } uploadID := mustGetUUID() @@ -543,7 +542,10 @@ func (er erasureObjects) GetMultipartInfo(ctx context.Context, bucket, object, u 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 } @@ -591,7 +593,10 @@ func (er erasureObjects) ListObjectParts(ctx context.Context, bucket, object, up result.UploadID = uploadID result.MaxParts = maxParts 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. if len(fi.Parts) == 0 || maxParts == 0 { diff --git a/cmd/fs-v1.go b/cmd/fs-v1.go index d507cf916..aa9f420d6 100644 --- a/cmd/fs-v1.go +++ b/cmd/fs-v1.go @@ -635,7 +635,10 @@ func (fs *FSObjects) CopyObject(ctx context.Context, srcBucket, srcObject, dstBu 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 if _, err = fsMeta.WriteTo(wlk); err != nil { 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. func (fs *FSObjects) createFsJSON(object, fsMetaPath string) error { fsMeta := newFSMetaV1() - fsMeta.Meta = make(map[string]string) - fsMeta.Meta["etag"] = GenETag() - contentType := mimedb.TypeByExtension(path.Ext(object)) - fsMeta.Meta["content-type"] = contentType + fsMeta.Meta = map[string]string{ + "etag": GenETag(), + "content-type": mimedb.TypeByExtension(path.Ext(object)), + } wlk, werr := fs.rwPool.Create(fsMetaPath) if werr == nil { _, 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. func (fs *FSObjects) defaultFsJSON(object string) fsMetaV1 { fsMeta := newFSMetaV1() - fsMeta.Meta = make(map[string]string) - fsMeta.Meta["etag"] = defaultEtag - contentType := mimedb.TypeByExtension(path.Ext(object)) - fsMeta.Meta["content-type"] = contentType + fsMeta.Meta = map[string]string{ + "etag": defaultEtag, + "content-type": mimedb.TypeByExtension(path.Ext(object)), + } return fsMeta }