Merge pull request #610 from harshavardhana/pr_out_fix_some_donut_todo_s_regarding_bucket_created_date

master
Harshavardhana 10 years ago
commit 138288f788
  1. 2
      pkg/storage/donut/donut_public_interfaces.go
  2. 16
      pkg/storage/donut/donut_test.go
  3. 22
      pkg/storage/donut/objectstorage.go
  4. 9
      pkg/storage/drivers/donut/donut.go

@ -31,7 +31,7 @@ type ObjectStorage interface {
// Storage service Operations
GetBucketMetadata(bucket string) (map[string]string, error)
SetBucketMetadata(bucket string, metadata map[string]string) error
ListBuckets() ([]string, error)
ListBuckets() (map[string]map[string]string, error)
MakeBucket(bucket, acl string) error
// Bucket Operations

@ -62,9 +62,9 @@ func (s *MySuite) TestEmptyDonut(c *C) {
c.Assert(err, IsNil)
// check donut is empty
buckets, err := donut.ListBuckets()
metadata, err := donut.ListBuckets()
c.Assert(err, IsNil)
c.Assert(buckets, IsNil)
c.Assert(len(metadata), Equals, 0)
}
// test make bucket without name
@ -112,7 +112,8 @@ func (s *MySuite) TestMakeBucketAndList(c *C) {
// check bucket exists
buckets, err := donut.ListBuckets()
c.Assert(err, IsNil)
c.Assert(buckets, DeepEquals, []string{"foo"})
c.Assert(len(buckets), Equals, 1)
c.Assert(buckets["foo"]["acl"], Equals, "private")
}
// test re-create bucket
@ -145,14 +146,19 @@ func (s *MySuite) TestCreateMultipleBucketsAndList(c *C) {
buckets, err := donut.ListBuckets()
c.Assert(err, IsNil)
c.Assert(buckets, DeepEquals, []string{"bar", "foo"})
_, ok := buckets["foo"]
c.Assert(ok, Equals, true)
_, ok = buckets["bar"]
c.Assert(ok, Equals, true)
err = donut.MakeBucket("foobar", "private")
c.Assert(err, IsNil)
buckets, err = donut.ListBuckets()
c.Assert(err, IsNil)
c.Assert(buckets, DeepEquals, []string{"bar", "foo", "foobar"})
_, ok = buckets["foobar"]
c.Assert(ok, Equals, true)
}
// test object create without bucket

@ -19,7 +19,6 @@ package donut
import (
"errors"
"io"
"os"
"sort"
"strconv"
"strings"
@ -69,25 +68,20 @@ func (d donut) SetBucketMetadata(bucket string, bucketMetadata map[string]string
}
// ListBuckets - return list of buckets
func (d donut) ListBuckets() (results []string, err error) {
func (d donut) ListBuckets() (metadata map[string]map[string]string, err error) {
err = d.getDonutBuckets()
if err != nil {
return nil, iodine.New(err, nil)
}
metadata, err := d.getDonutBucketMetadata()
dummyMetadata := make(map[string]map[string]string)
metadata, err = d.getDonutBucketMetadata()
if err != nil {
err = iodine.ToError(err)
if os.IsNotExist(err) {
// valid case
return nil, nil
}
return nil, iodine.New(err, nil)
// intentionally left out the error when Donut is empty
// but we need to revisit this area in future - since we need
// to figure out between acceptable and unacceptable errors
return dummyMetadata, nil
}
for name := range metadata {
results = append(results, name)
}
sort.Strings(results)
return results, nil
return metadata, nil
}
// ListObjects - return list of objects

@ -134,11 +134,14 @@ func (d donutDriver) ListBuckets() (results []drivers.BucketMetadata, err error)
if err != nil {
return nil, err
}
for _, name := range buckets {
for name, metadata := range buckets {
created, err := time.Parse(time.RFC3339Nano, metadata["created"])
if err != nil {
return nil, iodine.New(err, nil)
}
result := drivers.BucketMetadata{
Name: name,
// TODO Add real created date
Created: time.Now().UTC(),
Created: created,
}
results = append(results, result)
}

Loading…
Cancel
Save