Merge pull request #78 from harshavardhana/pr_out_add_list_buckets_for_fs

master
Harshavardhana 10 years ago
commit cc54730eee
  1. 26
      pkg/storage/fs/fs.go
  2. 9
      pkg/storage/storage_errors.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 {

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

Loading…
Cancel
Save