Get object metadata needs to filter based of Prefix when delimiter is specified

master
Harshavardhana 10 years ago
parent df69038b04
commit f8e2b75e23
  1. 14
      pkg/api/minioapi/api_test.go
  2. 4
      pkg/api/minioapi/object_handlers.go
  3. 21
      pkg/storage/fs/fs.go
  4. 2
      pkg/storage/inmemory/inmemory.go
  5. 2
      pkg/storage/storage.go
  6. 9
      pkg/storage/storage_api_suite.go

@ -71,7 +71,7 @@ func (s *MySuite) TestEmptyObject(c *C) {
c.Assert(err, IsNil)
c.Assert(true, Equals, bytes.Equal(responseBody, buffer.Bytes()))
metadata, err := storage.GetObjectMetadata("bucket", "object")
metadata, err := storage.GetObjectMetadata("bucket", "object", "")
c.Assert(err, IsNil)
verifyHeaders(c, response.Header, metadata.Created, 0, "application/octet-stream", metadata.ETag)
@ -96,7 +96,7 @@ func (s *MySuite) TestObject(c *C) {
c.Assert(err, IsNil)
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello world")))
metadata, err := storage.GetObjectMetadata("bucket", "object")
metadata, err := storage.GetObjectMetadata("bucket", "object", "")
c.Assert(err, IsNil)
verifyHeaders(c, response.Header, metadata.Created, len("hello world"), "application/octet-stream", metadata.ETag)
}
@ -129,7 +129,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
c.Assert(err, IsNil)
// get metadata
metadata, err := storage.GetObjectMetadata("bucket", "object1")
metadata, err := storage.GetObjectMetadata("bucket", "object1", "")
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
@ -148,7 +148,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
c.Assert(err, IsNil)
// get metadata
metadata, err = storage.GetObjectMetadata("bucket", "object2")
metadata, err = storage.GetObjectMetadata("bucket", "object2", "")
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
@ -167,7 +167,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
c.Assert(err, IsNil)
// get metadata
metadata, err = storage.GetObjectMetadata("bucket", "object3")
metadata, err = storage.GetObjectMetadata("bucket", "object3", "")
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
@ -210,7 +210,7 @@ func (s *MySuite) TestHeader(c *C) {
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
metadata, err := storage.GetObjectMetadata("bucket", "object")
metadata, err := storage.GetObjectMetadata("bucket", "object", "")
c.Assert(err, IsNil)
verifyHeaders(c, response.Header, metadata.Created, len("hello world"), "application/octet-stream", metadata.ETag)
}
@ -289,7 +289,7 @@ func (s *MySuite) TestPutObject(c *C) {
c.Assert(bytes.Equal(writer.Bytes(), []byte("hello world")), Equals, true)
metadata, err := storage.GetObjectMetadata("bucket", "two")
metadata, err := storage.GetObjectMetadata("bucket", "two", "")
c.Assert(err, IsNil)
lastModified := metadata.Created

@ -36,7 +36,7 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques
bucket = vars["bucket"]
object = vars["object"]
metadata, err := server.storage.GetObjectMetadata(bucket, object)
metadata, err := server.storage.GetObjectMetadata(bucket, object, "")
switch err := err.(type) {
case nil: // success
{
@ -89,7 +89,7 @@ func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Reque
bucket = vars["bucket"]
object = vars["object"]
metadata, err := server.storage.GetObjectMetadata(bucket, object)
metadata, err := server.storage.GetObjectMetadata(bucket, object, "")
switch err := err.(type) {
case nil:
writeObjectHeaders(w, metadata)

@ -261,7 +261,7 @@ func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object st
}
// GetObjectMetadata - HEAD object
func (storage *Storage) GetObjectMetadata(bucket, object string) (mstorage.ObjectMetadata, error) {
func (storage *Storage) GetObjectMetadata(bucket, object, prefix string) (mstorage.ObjectMetadata, error) {
if mstorage.IsValidBucket(bucket) == false {
return mstorage.ObjectMetadata{}, mstorage.BucketNameInvalid{Bucket: bucket}
}
@ -291,7 +291,6 @@ func (storage *Storage) GetObjectMetadata(bucket, object string) (mstorage.Objec
var deserializedMetadata Metadata
decoder := gob.NewDecoder(file)
err = decoder.Decode(&deserializedMetadata)
if err != nil {
return mstorage.ObjectMetadata{}, mstorage.EmbedError(bucket, object, err)
}
@ -306,9 +305,10 @@ func (storage *Storage) GetObjectMetadata(bucket, object string) (mstorage.Objec
if len(deserializedMetadata.Md5sum) != 0 {
etag = hex.EncodeToString(deserializedMetadata.Md5sum)
}
trimmedObject := strings.TrimPrefix(object, prefix)
metadata := mstorage.ObjectMetadata{
Bucket: bucket,
Key: path.Base(object),
Key: trimmedObject,
Created: stat.ModTime(),
Size: stat.Size(),
ETag: etag,
@ -395,13 +395,15 @@ func (storage *Storage) ListObjects(bucket string, resources mstorage.BucketReso
delimitedName := delimiter(name, resources.Delimiter)
switch true {
case delimitedName == "":
metadata, err := storage.GetObjectMetadata(bucket, name)
// Do not strip prefix object output
metadata, err := storage.GetObjectMetadata(bucket, name, "")
if err != nil {
return []mstorage.ObjectMetadata{}, resources, mstorage.EmbedError(bucket, "", err)
}
metadataList = append(metadataList, metadata)
case delimitedName == file.Name():
metadata, err := storage.GetObjectMetadata(bucket, name)
// Do not strip prefix object output
metadata, err := storage.GetObjectMetadata(bucket, name, "")
if err != nil {
return []mstorage.ObjectMetadata{}, resources, mstorage.EmbedError(bucket, "", err)
}
@ -414,13 +416,15 @@ func (storage *Storage) ListObjects(bucket string, resources mstorage.BucketReso
delimitedName := delimiter(trimmedName, resources.Delimiter)
switch true {
case name == resources.Prefix:
metadata, err := storage.GetObjectMetadata(bucket, name)
// Use resources.Prefix to filter out delimited files
metadata, err := storage.GetObjectMetadata(bucket, name, resources.Prefix)
if err != nil {
return []mstorage.ObjectMetadata{}, resources, mstorage.EmbedError(bucket, "", err)
}
metadataList = append(metadataList, metadata)
case delimitedName == file.Name():
metadata, err := storage.GetObjectMetadata(bucket, name)
// Use resources.Prefix to filter out delimited files
metadata, err := storage.GetObjectMetadata(bucket, name, resources.Prefix)
if err != nil {
return []mstorage.ObjectMetadata{}, resources, mstorage.EmbedError(bucket, "", err)
}
@ -433,7 +437,8 @@ func (storage *Storage) ListObjects(bucket string, resources mstorage.BucketReso
}
}
case strings.HasPrefix(name, resources.Prefix):
metadata, err := storage.GetObjectMetadata(bucket, name)
// Do not strip prefix object output
metadata, err := storage.GetObjectMetadata(bucket, name, "")
if err != nil {
return []mstorage.ObjectMetadata{}, resources, mstorage.EmbedError(bucket, "", err)
}

@ -198,7 +198,7 @@ func (storage *Storage) ListBuckets() ([]mstorage.BucketMetadata, error) {
}
// GetObjectMetadata - get object metadata from memory
func (storage *Storage) GetObjectMetadata(bucket, key string) (mstorage.ObjectMetadata, error) {
func (storage *Storage) GetObjectMetadata(bucket, key, prefix string) (mstorage.ObjectMetadata, error) {
objectKey := bucket + ":" + key
if object, ok := storage.objectdata[objectKey]; ok == true {

@ -33,7 +33,7 @@ type Storage interface {
// Object Operations
CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error)
GetObjectMetadata(bucket string, object string) (ObjectMetadata, error)
GetObjectMetadata(bucket string, object string, prefix string) (ObjectMetadata, error)
ListObjects(bucket string, resources BucketResourcesMetadata) ([]ObjectMetadata, BucketResourcesMetadata, error)
StoreObject(bucket string, key string, contentType string, data io.Reader) error
}

@ -69,7 +69,7 @@ func testMultipleObjectCreation(c *check.C, create func() Storage) {
storage.CopyObjectToWriter(&byteBuffer, "bucket", key)
c.Assert(bytes.Equal(value, byteBuffer.Bytes()), check.Equals, true)
metadata, err := storage.GetObjectMetadata("bucket", key)
metadata, err := storage.GetObjectMetadata("bucket", key, "")
c.Assert(err, check.IsNil)
c.Assert(metadata.Size, check.Equals, int64(len(value)))
@ -133,6 +133,7 @@ func testPaging(c *check.C, create func() Storage) {
resources.Prefix = "obj"
resources.Maxkeys = 1000
objects, resources, err = storage.ListObjects("bucket", resources)
c.Log(objects)
c.Assert(objects[0].Key, check.Equals, "obj0")
c.Assert(objects[1].Key, check.Equals, "obj1")
c.Assert(objects[2].Key, check.Equals, "obj10")
@ -320,19 +321,19 @@ func testDefaultContentType(c *check.C, create func() Storage) {
// test empty
err = storage.StoreObject("bucket", "one", "", bytes.NewBufferString("one"))
metadata, err := storage.GetObjectMetadata("bucket", "one")
metadata, err := storage.GetObjectMetadata("bucket", "one", "")
c.Assert(err, check.IsNil)
c.Assert(metadata.ContentType, check.Equals, "application/octet-stream")
// test custom
storage.StoreObject("bucket", "two", "application/text", bytes.NewBufferString("two"))
metadata, err = storage.GetObjectMetadata("bucket", "two")
metadata, err = storage.GetObjectMetadata("bucket", "two", "")
c.Assert(err, check.IsNil)
c.Assert(metadata.ContentType, check.Equals, "application/text")
// test trim space
storage.StoreObject("bucket", "three", "\tapplication/json ", bytes.NewBufferString("three"))
metadata, err = storage.GetObjectMetadata("bucket", "three")
metadata, err = storage.GetObjectMetadata("bucket", "three", "")
c.Assert(err, check.IsNil)
c.Assert(metadata.ContentType, check.Equals, "application/json")
}

Loading…
Cancel
Save