Merge pull request #61 from fkautz/pr_out_adding_istruncated_to_minioapi

master
Frederick F. Kautz IV 10 years ago
commit b181ca7395
  1. 10
      pkg/storage/inmemory/inmemory.go
  2. 2
      pkg/storage/storage.go
  3. 12
      pkg/storage/storage_api_suite.go
  4. 8
      pkg/webapi/minioapi/minioapi.go
  5. 4
      pkg/webapi/minioapi/minioapi_test.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 {

@ -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 {

@ -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)
}
}

@ -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
}

@ -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

Loading…
Cancel
Save