When updating the meta file, write to temp file first and then rename to the actual location.

This prevents appending the metadata to the metadata-file when a file is reuploaded.
This commit is contained in:
Krishna Srinivas 2016-08-16 03:32:19 +05:30 committed by Harshavardhana
parent 0e745fdb05
commit bb8a425d49
2 changed files with 11 additions and 5 deletions

View File

@ -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. // Save additional metadata only if extended headers such as "X-Amz-Meta-" are set.
if hasExtendedHeader(fsMeta.Meta) { if hasExtendedHeader(fsMeta.Meta) {
fsMeta.Meta["md5Sum"] = s3MD5 fsMeta.Meta["md5Sum"] = s3MD5
uniqueID := getUUID()
fsMetaTmp := path.Join(tmpMetaPrefix, uniqueID) // Write the metadata to a temp file and rename it to the actual location.
if err = writeFSMetadata(fs.storage, minioMetaBucket, fsMetaTmp, fsMeta); err != nil { tmpMetaPath := path.Join(tmpMetaPrefix, getUUID())
if err = writeFSMetadata(fs.storage, minioMetaBucket, tmpMetaPath, fsMeta); err != nil {
return "", toObjectErr(err, bucket, object) return "", toObjectErr(err, bucket, object)
} }
fsMetaPath := path.Join(bucketMetaPrefix, bucket, object, fsMetaJSONFile) 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) return "", toObjectErr(err, bucket, object)
} }
} }

View File

@ -456,8 +456,13 @@ func (fs fsObjects) PutObject(bucket string, object string, size int64, data io.
fsMeta := newFSMetaV1() fsMeta := newFSMetaV1()
fsMeta.Meta = metadata 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) 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) return "", toObjectErr(err, bucket, object)
} }
} }