mirror of
https://github.com/minio/minio.git
synced 2025-12-08 16:53:11 -05:00
Add list() object support for erasure and append storage drivers
- Reply back objects with their protectionlevel and md5sum - // TODO hash value - Calculate md5sum after "storeBlocks()", to make sure data is committed
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/gob"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -93,8 +94,20 @@ func (eStorage *encodedStorage) Get(objectPath string) (io.Reader, error) {
|
||||
return reader, nil
|
||||
}
|
||||
|
||||
func (eStorage *encodedStorage) List(listPath string) ([]storage.ObjectDescription, error) {
|
||||
return nil, errors.New("Not Implemented")
|
||||
func (eStorage *encodedStorage) List() ([]storage.ObjectDescription, error) {
|
||||
var objectDescList []storage.ObjectDescription
|
||||
for objectName, objectEntry := range eStorage.objects {
|
||||
var objectDescription storage.ObjectDescription
|
||||
protectionLevel := strconv.Itoa(objectEntry.Encoderparams.K) + "," + strconv.Itoa(objectEntry.Encoderparams.M)
|
||||
objectDescription.Name = objectName
|
||||
objectDescription.Md5sum = hex.EncodeToString(objectEntry.Md5sum)
|
||||
objectDescription.Protectionlevel = protectionLevel
|
||||
objectDescList = append(objectDescList, objectDescription)
|
||||
}
|
||||
if len(objectDescList) == 0 {
|
||||
return nil, errors.New("No objects found")
|
||||
}
|
||||
return objectDescList, nil
|
||||
}
|
||||
|
||||
func (eStorage *encodedStorage) Put(objectPath string, object io.Reader) error {
|
||||
@@ -124,8 +137,6 @@ func (eStorage *encodedStorage) Put(objectPath string, object io.Reader) error {
|
||||
// encode
|
||||
for chunk := range chunks {
|
||||
if chunk.Err == nil {
|
||||
// md5sum on chunk
|
||||
hash.Write(chunk.Data)
|
||||
// encode each
|
||||
blocks, length := encoder.Encode(chunk.Data)
|
||||
// store each
|
||||
@@ -135,6 +146,8 @@ func (eStorage *encodedStorage) Put(objectPath string, object io.Reader) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// md5sum only after chunk is committed to disk
|
||||
hash.Write(chunk.Data)
|
||||
blockEntry := StorageBlockEntry{
|
||||
Index: i,
|
||||
Length: length,
|
||||
|
||||
@@ -38,9 +38,9 @@ func (s *EncodedStorageSuite) TestFileStoragePutAtRootPath(c *C) {
|
||||
object1, _ := ioutil.ReadAll(objectResult1)
|
||||
c.Assert(string(object1), Equals, "object1")
|
||||
|
||||
// objectList, err := objectStorage.List("/")
|
||||
// c.Assert(err, IsNil)
|
||||
// c.Assert(objectList[0].Path, Equals, "path1")
|
||||
objectList, err := objectStorage.List()
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(objectList[0].Name, Equals, "path1")
|
||||
}
|
||||
|
||||
func (s *EncodedStorageSuite) TestFileStoragePutDirPath(c *C) {
|
||||
@@ -70,28 +70,6 @@ func (s *EncodedStorageSuite) TestFileStoragePutDirPath(c *C) {
|
||||
objectBuffer3 := bytes.NewBuffer([]byte("object3"))
|
||||
err = objectStorage.Put("object3", objectBuffer3)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// TODO support list
|
||||
// objectList, err := objectStorage.List("/")
|
||||
// c.Assert(err, IsNil)
|
||||
// c.Assert(objectList[0], Equals, storage.ObjectDescription{Path: "object3", IsDir: false, Hash: ""})
|
||||
// c.Assert(objectList[1], Equals, storage.ObjectDescription{Path: "path1", IsDir: true, Hash: ""})
|
||||
// c.Assert(objectList[2], Equals, storage.ObjectDescription{Path: "path2", IsDir: true, Hash: ""})
|
||||
// c.Assert(len(objectList), Equals, 3)
|
||||
//
|
||||
// objectList, err = objectStorage.List("/path1")
|
||||
// c.Assert(err, IsNil)
|
||||
// c.Assert(objectList[0], Equals, storage.ObjectDescription{Path: "path2", IsDir: true, Hash: ""})
|
||||
// c.Assert(len(objectList), Equals, 1)
|
||||
//
|
||||
// objectList, err = objectStorage.List("/path1/path2")
|
||||
// c.Assert(err, IsNil)
|
||||
// c.Assert(objectList[0], Equals, storage.ObjectDescription{Path: "path3", IsDir: false, Hash: ""})
|
||||
// c.Assert(len(objectList), Equals, 1)
|
||||
//
|
||||
// objectList, err = objectStorage.List("/path1/path2/path3")
|
||||
// c.Assert(err, Not(IsNil))
|
||||
// c.Assert(objectList, IsNil)
|
||||
}
|
||||
|
||||
func (s *EncodedStorageSuite) TestObjectWithChunking(c *C) {
|
||||
|
||||
Reference in New Issue
Block a user