Merge pull request #61 from fkautz/pr_out_adding_istruncated_to_minioapi

This commit is contained in:
Frederick F. Kautz IV 2015-01-25 13:33:19 -08:00
commit b181ca7395
5 changed files with 21 additions and 15 deletions

View File

@ -86,20 +86,20 @@ func (storage *storage) StoreBucket(bucketName string) error {
return nil
}
func (storage *storage) ListObjects(bucket, prefix string, count int) []mstorage.ObjectMetadata {
func (storage *storage) ListObjects(bucket, prefix string, count int) ([]mstorage.ObjectMetadata, bool) {
// TODO prefix and count handling
var results []mstorage.ObjectMetadata
for key, object := range storage.objectdata {
if len(results) == count {
return results, true
}
if bucket == object.metadata.Bucket {
if strings.HasPrefix(key, bucket+":") {
results = append(results, object.metadata)
}
}
if len(results) == count {
return results
}
}
return results
return results, false
}
func (storage *storage) ListBuckets(prefix string) []mstorage.BucketMetadata {

View File

@ -31,7 +31,7 @@ type Storage interface {
GetObjectMetadata(bucket string, object string) (ObjectMetadata, error)
CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error)
StoreObject(bucket string, key string, data io.Reader) error
ListObjects(bucket, prefix string, count int) []ObjectMetadata
ListObjects(bucket, prefix string, count int) ([]ObjectMetadata, bool)
}
type BucketMetadata struct {

View File

@ -61,16 +61,22 @@ func testPaging(c *C, create func() Storage) {
storage := create()
storage.StoreBucket("bucket")
storage.ListObjects("bucket", "", 1000)
c.Assert(len(storage.ListObjects("bucket", "", 1000)), Equals, 0)
objects, isTruncated := storage.ListObjects("bucket", "", 1000)
c.Assert(len(objects), Equals, 0)
c.Assert(isTruncated, Equals, false)
for i := 1; i <= 1000; i++ {
key := "obj" + strconv.Itoa(i)
storage.StoreObject("bucket", key, bytes.NewBufferString(key))
c.Assert(len(storage.ListObjects("bucket", "", i)), Equals, i)
objects, isTruncated = storage.ListObjects("bucket", "", 1000)
c.Assert(len(objects), Equals, i)
c.Assert(isTruncated, Equals, false)
}
for i := 1001; i <= 2000; i++ {
key := "obj" + strconv.Itoa(i)
storage.StoreObject("bucket", key, bytes.NewBufferString(key))
c.Assert(len(storage.ListObjects("bucket", "", 1000)), Equals, 1000)
objects, isTruncated = storage.ListObjects("bucket", "", 1000)
c.Assert(len(objects), Equals, 1000)
c.Assert(isTruncated, Equals, true)
}
}

View File

@ -189,8 +189,8 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
}
}
objects := server.storage.ListObjects(bucket, prefix, 1000)
response := generateObjectsListResult(bucket, objects)
objects, isTruncated := server.storage.ListObjects(bucket, prefix, 1000)
response := generateObjectsListResult(bucket, objects, isTruncated)
var bytesBuffer bytes.Buffer
var encoder encoder
@ -269,7 +269,7 @@ func generateBucketsListResult(buckets []mstorage.BucketMetadata) BucketListResp
return data
}
func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata) ObjectListResponse {
func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata, isTruncated bool) ObjectListResponse {
var contents []*Item
var owner = Owner{}
var data = ObjectListResponse{}
@ -290,6 +290,6 @@ func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata)
data.Name = bucket
data.Contents = contents
data.MaxKeys = MAX_OBJECT_LIST
data.IsTruncated = false
data.IsTruncated = isTruncated
return data
}

View File

@ -237,7 +237,7 @@ func (s *MySuite) TestPutObject(c *C) {
testServer := httptest.NewServer(httpHandler)
defer testServer.Close()
objects := storage.ListObjects("bucket", "", 1000)
objects, _ := storage.ListObjects("bucket", "", 1000)
c.Assert(len(objects), Equals, 0)
date1 := time.Now()
@ -260,7 +260,7 @@ func (s *MySuite) TestPutObject(c *C) {
date2 := time.Now()
objects = storage.ListObjects("bucket", "", 1000)
objects, _ = storage.ListObjects("bucket", "", 1000)
c.Assert(len(objects), Equals, 1)
var writer bytes.Buffer