diff --git a/fs-v1-multipart.go b/fs-v1-multipart.go index b494d94bf..3c19e1ca6 100644 --- a/fs-v1-multipart.go +++ b/fs-v1-multipart.go @@ -588,13 +588,14 @@ func (fs fsObjects) CompleteMultipartUpload(bucket string, object string, upload // Save additional metadata only if extended headers such as "X-Amz-Meta-" are set. if hasExtendedHeader(fsMeta.Meta) { fsMeta.Meta["md5Sum"] = s3MD5 - uniqueID := getUUID() - fsMetaTmp := path.Join(tmpMetaPrefix, uniqueID) - if err = writeFSMetadata(fs.storage, minioMetaBucket, fsMetaTmp, fsMeta); err != nil { + + // Write the metadata to a temp file and rename it to the actual location. + tmpMetaPath := path.Join(tmpMetaPrefix, getUUID()) + if err = writeFSMetadata(fs.storage, minioMetaBucket, tmpMetaPath, fsMeta); err != nil { return "", toObjectErr(err, bucket, object) } fsMetaPath := path.Join(bucketMetaPrefix, bucket, object, fsMetaJSONFile) - if err = fs.storage.RenameFile(minioMetaBucket, fsMetaTmp, minioMetaBucket, fsMetaPath); err != nil { + if err = fs.storage.RenameFile(minioMetaBucket, tmpMetaPath, minioMetaBucket, fsMetaPath); err != nil { return "", toObjectErr(err, bucket, object) } } diff --git a/fs-v1.go b/fs-v1.go index 8a4261e6e..c4fea4b07 100644 --- a/fs-v1.go +++ b/fs-v1.go @@ -456,8 +456,13 @@ func (fs fsObjects) PutObject(bucket string, object string, size int64, data io. fsMeta := newFSMetaV1() fsMeta.Meta = metadata + // Write the metadata to a temp file and rename it to the actual location. + tmpMetaPath := path.Join(tmpMetaPrefix, getUUID()) fsMetaPath := path.Join(bucketMetaPrefix, bucket, object, fsMetaJSONFile) - if err = writeFSMetadata(fs.storage, minioMetaBucket, fsMetaPath, fsMeta); err != nil { + if err = writeFSMetadata(fs.storage, minioMetaBucket, tmpMetaPath, fsMeta); err != nil { + return "", toObjectErr(err, bucket, object) + } + if err = fs.storage.RenameFile(minioMetaBucket, tmpMetaPath, minioMetaBucket, fsMetaPath); err != nil { return "", toObjectErr(err, bucket, object) } }