From a00a5c6e7e767afd069e737005faf1dfe688a2c6 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 24 May 2016 13:35:43 -0700 Subject: [PATCH] XL: Multipart update uploads.json properly. (#1741) --- xl-v1-metadata.go | 4 +++- xl-v1-multipart-common.go | 12 +++--------- xl-v1-multipart.go | 15 ++++++++++++--- xl-v1-object.go | 2 -- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/xl-v1-metadata.go b/xl-v1-metadata.go index c11ae2ed5..aa31616f9 100644 --- a/xl-v1-metadata.go +++ b/xl-v1-metadata.go @@ -77,7 +77,7 @@ func (m *xlMetaV1) ReadFrom(reader io.Reader) (n int64, err error) { // WriteTo - write to implements io.WriterTo interface for marshalling xlMetaV1. func (m xlMetaV1) WriteTo(writer io.Writer) (n int64, err error) { - metadataBytes, err := json.Marshal(m) + metadataBytes, err := json.Marshal(&m) if err != nil { return 0, err } @@ -231,6 +231,8 @@ func (xl xlObjects) writeXLMetadata(bucket, prefix string, xlMeta xlMetaV1) erro var mErrs = make([]error, len(xl.storageDisks)) // Initialize metadata map, save all erasure related metadata. + xlMeta.Version = "1" + xlMeta.Format = "xl" xlMeta.Minio.Release = minioReleaseTag xlMeta.Erasure.DataBlocks = xl.dataBlocks xlMeta.Erasure.ParityBlocks = xl.parityBlocks diff --git a/xl-v1-multipart-common.go b/xl-v1-multipart-common.go index ee9b057c6..3aecfae87 100644 --- a/xl-v1-multipart-common.go +++ b/xl-v1-multipart-common.go @@ -82,7 +82,7 @@ func (u *uploadsV1) ReadFrom(reader io.Reader) (n int64, err error) { // WriteTo - write to implements io.WriterTo interface for marshalling uploads. func (u uploadsV1) WriteTo(writer io.Writer) (n int64, err error) { - metadataBytes, err := json.Marshal(u) + metadataBytes, err := json.Marshal(&u) if err != nil { return 0, err } @@ -206,15 +206,8 @@ func writeUploadJSON(bucket, object, uploadID string, initiated time.Time, stora errs[index] = wErr return } - - _, wErr = disk.StatFile(minioMetaBucket, uploadsPath) + wErr = disk.RenameFile(minioMetaBucket, tmpUploadsPath, minioMetaBucket, uploadsPath) if wErr != nil { - if wErr == errFileNotFound { - wErr = disk.RenameFile(minioMetaBucket, tmpUploadsPath, minioMetaBucket, uploadsPath) - if wErr == nil { - return - } - } if dErr := disk.DeleteFile(minioMetaBucket, tmpUploadsPath); dErr != nil { errs[index] = dErr return @@ -222,6 +215,7 @@ func writeUploadJSON(bucket, object, uploadID string, initiated time.Time, stora errs[index] = wErr return } + errs[index] = nil }(index, disk) } diff --git a/xl-v1-multipart.go b/xl-v1-multipart.go index c3928e30e..513c6bedf 100644 --- a/xl-v1-multipart.go +++ b/xl-v1-multipart.go @@ -23,8 +23,12 @@ import ( "io" "io/ioutil" "path" + "path/filepath" "strconv" + "strings" "time" + + "github.com/minio/minio/pkg/mimedb" ) // ListMultipartUploads - list multipart uploads. @@ -54,11 +58,16 @@ func (xl xlObjects) newMultipartUploadCommon(bucket string, object string, meta } xlMeta := xlMetaV1{} - xlMeta.Format = "xl" - xlMeta.Version = "1" // If not set default to "application/octet-stream" if meta["content-type"] == "" { - meta["content-type"] = "application/octet-stream" + contentType := "application/octet-stream" + if objectExt := filepath.Ext(object); objectExt != "" { + content, ok := mimedb.DB[strings.ToLower(strings.TrimPrefix(objectExt, "."))] + if ok { + contentType = content.ContentType + } + } + meta["content-type"] = contentType } xlMeta.Meta = meta diff --git a/xl-v1-object.go b/xl-v1-object.go index 5b81e4c08..9979087c1 100644 --- a/xl-v1-object.go +++ b/xl-v1-object.go @@ -280,8 +280,6 @@ func (xl xlObjects) PutObject(bucket string, object string, size int64, data io. } xlMeta := xlMetaV1{} - xlMeta.Version = "1" - xlMeta.Format = "xl" xlMeta.Meta = metadata xlMeta.Stat.Size = size xlMeta.Stat.ModTime = modTime