From 598eb5192e0dfbb862a09397732abad2ea0802db Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Tue, 17 Mar 2015 00:29:19 -0700 Subject: [PATCH] Encoded now passes tests, enabling. --- pkg/donutbox/donutmem/donutmem.go | 4 +++- pkg/storage/encoded/encoded.go | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/donutbox/donutmem/donutmem.go b/pkg/donutbox/donutmem/donutmem.go index 51fd86cb3..28dcd4f19 100644 --- a/pkg/donutbox/donutmem/donutmem.go +++ b/pkg/donutbox/donutmem/donutmem.go @@ -8,6 +8,7 @@ import ( "strconv" "strings" "sync" + "time" ) type bucket struct { @@ -58,6 +59,7 @@ func (donutMem donutMem) CreateBucket(b string) error { } metadata := make(map[string]string) metadata["name"] = b + metadata["created"] = time.Now().Format(time.RFC3339Nano) newBucket := bucket{ name: b, metadata: metadata, @@ -234,7 +236,7 @@ func (donutMem donutMem) GetObjectMetadata(bucketKey, objectKey string, column u } return result, nil } - return nil, errors.New("Object not found") + return nil, errors.New("Object not Found: " + bucketKey + "#" + objectKey) } return nil, errors.New("Bucket not found") } diff --git a/pkg/storage/encoded/encoded.go b/pkg/storage/encoded/encoded.go index 2d5f119c0..33bf13b01 100644 --- a/pkg/storage/encoded/encoded.go +++ b/pkg/storage/encoded/encoded.go @@ -62,21 +62,29 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error, s *StorageDrive } // ListBuckets returns a list of buckets -func (diskStorage StorageDriver) ListBuckets() ([]storage.BucketMetadata, error) { +func (diskStorage StorageDriver) ListBuckets() (results []storage.BucketMetadata, err error) { buckets, err := diskStorage.donutBox.ListBuckets() if err != nil { return nil, err } - var results []storage.BucketMetadata sort.Strings(buckets) for _, bucket := range buckets { - bucketMetadata, err := diskStorage.GetBucketMetadata(bucket) + metadata, err := diskStorage.donutBox.GetBucketMetadata(bucket) if err != nil { return nil, err } + + created, err := time.Parse(time.RFC3339Nano, metadata["created"]) + if err != nil { + return nil, err + } + bucketMetadata := storage.BucketMetadata{ + Name: bucket, + Created: created, + } results = append(results, bucketMetadata) } - return results, nil + return results, err } // CreateBucket creates a new bucket @@ -124,7 +132,8 @@ func (diskStorage StorageDriver) GetBucketPolicy(bucket string) (storage.BucketP // GetObject retrieves an object and writes it to a writer func (diskStorage StorageDriver) GetObject(target io.Writer, bucket, key string) (int64, error) { metadata, err := diskStorage.donutBox.GetObjectMetadata(bucket, key, 0) - if len(metadata) == 0 { + if err != nil { + // TODO strongly type and properly handle error cases return 0, storage.ObjectNotFound{Bucket: bucket, Object: key} } k, err := strconv.Atoi(metadata["erasureK"]) @@ -282,6 +291,11 @@ func beforeDelimiter(inputs []string, delim string) (results []string) { // CreateObject creates a new object func (diskStorage StorageDriver) CreateObject(bucketKey string, objectKey string, contentType string, reader io.Reader) error { + // set defaults + if contentType == "" { + contentType = "application/octet-stream" + } + contentType = strings.TrimSpace(contentType) // split stream splitStream := split.Stream(reader, uint64(blockSize)) writers := make([]*donutbox.NewObject, 16)