diff --git a/pkg/storage/fs/fs.go b/pkg/storage/fs/fs.go index 1f3eb7ef8..e4dee516a 100644 --- a/pkg/storage/fs/fs.go +++ b/pkg/storage/fs/fs.go @@ -34,10 +34,32 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error) { close(errorChannel) } -// Bucket Operaotions +// Bucket Operations func (storage *storage) ListBuckets(prefix string) ([]mstorage.BucketMetadata, error) { - return []mstorage.BucketMetadata{}, errors.New("Not Implemented") + if mstorage.IsValidBucket(bucket) == false { + return []mstorage.BucketMetadata{}, mstorage.BucketNameInvalid{Bucket: bucket} + } + + files, err := ioutil.ReadDir(storage.root) + if err != nil { + return []mstorage.BucketMetadata{}, mstorage.EmbedError("bucket", "", err) + } + + var metadataList []mstorage.BucketMetadata + for _, file := range files { + if !file.IsDir() { + return []mstorage.BucketMetadata{}, mstorage.BackendCorrupted{Path: storage.root} + } + if strings.HasPrefix(file.Name(), prefix) { + metadata := mstorage.BucketMetadata{ + Name: file.Name(), + Created: file.ModTime(), // TODO - provide real created time + } + metadataList = append(metadata, metadataList) + } + } + return metadataList, nil } func (storage *storage) StoreBucket(bucket string) error { diff --git a/pkg/storage/storage_errors.go b/pkg/storage/storage_errors.go index 1e5ee05e9..19fa61dbb 100644 --- a/pkg/storage/storage_errors.go +++ b/pkg/storage/storage_errors.go @@ -1,5 +1,9 @@ package storage +type BackendError struct { + Path string +} + type GenericError struct { Bucket string Path string @@ -47,6 +51,7 @@ func EmbedError(bucket, object string, err error) ImplementationError { } } +type BackendCorrupted BackendError type BucketNameInvalid GenericBucketError type BucketExists GenericBucketError type BucketNotFound GenericBucketError @@ -75,3 +80,7 @@ func (self BucketNotFound) Error() string { func (self ObjectNameInvalid) Error() string { return "Object name invalid: " + self.Bucket + "#" + self.Object } + +func (self BackendCorrupted) Error() string { + return "Backend corrupted: " + self.Path +}