From d37bbfec41afe728336f72a85d1248f7ef6b946f Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Sun, 25 Jan 2015 13:32:39 -0800 Subject: [PATCH] Adding IsTruncated to minioapi --- pkg/storage/inmemory/inmemory.go | 10 +++++----- pkg/storage/storage.go | 2 +- pkg/storage/storage_api_suite.go | 12 +++++++++--- pkg/webapi/minioapi/minioapi.go | 8 ++++---- pkg/webapi/minioapi/minioapi_test.go | 4 ++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/pkg/storage/inmemory/inmemory.go b/pkg/storage/inmemory/inmemory.go index 7b74660c1..ba45f027f 100644 --- a/pkg/storage/inmemory/inmemory.go +++ b/pkg/storage/inmemory/inmemory.go @@ -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 { diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 8c69fbd9b..b3a143556 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -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 { diff --git a/pkg/storage/storage_api_suite.go b/pkg/storage/storage_api_suite.go index 02134cb10..d4e871fa2 100644 --- a/pkg/storage/storage_api_suite.go +++ b/pkg/storage/storage_api_suite.go @@ -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) } } diff --git a/pkg/webapi/minioapi/minioapi.go b/pkg/webapi/minioapi/minioapi.go index 5fade342a..07fdb6976 100644 --- a/pkg/webapi/minioapi/minioapi.go +++ b/pkg/webapi/minioapi/minioapi.go @@ -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 } diff --git a/pkg/webapi/minioapi/minioapi_test.go b/pkg/webapi/minioapi/minioapi_test.go index 8c3143863..7fa8b7af8 100644 --- a/pkg/webapi/minioapi/minioapi_test.go +++ b/pkg/webapi/minioapi/minioapi_test.go @@ -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