XL/objectLayer: Save additional meta data during PutObject (#1672)

Fixes  #1602
master
Bala FA 9 years ago committed by Harshavardhana
parent 824c8a39f1
commit a0865122a7
  1. 39
      xl-objects.go

@ -17,6 +17,7 @@
package main package main
import ( import (
"bytes"
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
@ -358,6 +359,40 @@ func (xl xlObjects) PutObject(bucket string, object string, size int64, data io.
return "", toObjectErr(err, bucket, object) return "", toObjectErr(err, bucket, object)
} }
metadataBytes, err := json.Marshal(metadata)
if err != nil {
return newMD5Hex, nil
}
tempMetaJSONFile := path.Join(tmpMetaPrefix, bucket, object, "meta.json")
fileWriter, err = xl.storage.CreateFile(minioMetaBucket, tempMetaJSONFile)
if err != nil {
return "", toObjectErr(err, bucket, object)
}
if _, err = io.Copy(fileWriter, bytes.NewReader(metadataBytes)); err != nil {
if clErr := safeCloseAndRemove(fileWriter); clErr != nil {
return "", toObjectErr(clErr, bucket, object)
}
return "", toObjectErr(err, bucket, object)
}
if err = fileWriter.Close(); err != nil {
if err = safeCloseAndRemove(fileWriter); err != nil {
return "", toObjectErr(err, bucket, object)
}
return "", toObjectErr(err, bucket, object)
}
metaJSONFile := path.Join(object, "meta.json")
err = xl.storage.RenameFile(minioMetaBucket, tempMetaJSONFile, bucket, metaJSONFile)
if err != nil {
if derr := xl.storage.DeleteFile(minioMetaBucket, tempMetaJSONFile); derr != nil {
return "", toObjectErr(derr, bucket, object)
}
return "", toObjectErr(err, bucket, object)
}
// Return md5sum, successfully wrote object. // Return md5sum, successfully wrote object.
return newMD5Hex, nil return newMD5Hex, nil
} }
@ -380,6 +415,10 @@ func (xl xlObjects) deleteObject(bucket, object string) error {
if ok, err := isMultipartObject(xl.storage, bucket, object); err != nil { if ok, err := isMultipartObject(xl.storage, bucket, object); err != nil {
return err return err
} else if !ok { } else if !ok {
metaJSONFile := path.Join(object, "meta.json")
if err = xl.storage.DeleteFile(bucket, metaJSONFile); err != nil {
return err
}
if err = xl.storage.DeleteFile(bucket, object); err != nil { if err = xl.storage.DeleteFile(bucket, object); err != nil {
return err return err
} }

Loading…
Cancel
Save