From 5cdf2564a5532a57292124fce3a1d800c1598ac2 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Thu, 26 Mar 2015 10:21:24 -0700 Subject: [PATCH] Adding iodine to node_local --- pkg/storage/donut/node_local.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/pkg/storage/donut/node_local.go b/pkg/storage/donut/node_local.go index cc1bb5e35..bb4e18da1 100644 --- a/pkg/storage/donut/node_local.go +++ b/pkg/storage/donut/node_local.go @@ -8,6 +8,7 @@ import ( "strings" "encoding/json" + "github.com/minio-io/iodine" "io/ioutil" "path/filepath" ) @@ -18,13 +19,13 @@ type localDirectoryNode struct { func (d localDirectoryNode) CreateBucket(bucket string) error { objectPath := path.Join(d.root, bucket) - return os.MkdirAll(objectPath, 0700) + return iodine.Error(os.MkdirAll(objectPath, 0700), map[string]string{"bucket": bucket}) } func (d localDirectoryNode) GetBuckets() ([]string, error) { files, err := ioutil.ReadDir(d.root) if err != nil { - return nil, err + return nil, iodine.Error(err, nil) } var results []string for _, file := range files { @@ -36,46 +37,53 @@ func (d localDirectoryNode) GetBuckets() ([]string, error) { } func (d localDirectoryNode) GetWriter(bucket, object string) (Writer, error) { + errParams := map[string]string{"bucket": bucket, "object": object} objectPath := path.Join(d.root, bucket, object) err := os.MkdirAll(objectPath, 0700) if err != nil { - return nil, err + return nil, iodine.Error(err, errParams) } - return newDonutObjectWriter(objectPath) + writer, err := newDonutObjectWriter(objectPath) + return writer, iodine.Error(err, errParams) } func (d localDirectoryNode) GetReader(bucket, object string) (io.ReadCloser, error) { - return os.Open(path.Join(d.root, bucket, object, "data")) + reader, err := os.Open(path.Join(d.root, bucket, object, "data")) + return reader, iodine.Error(err, map[string]string{"bucket": bucket, "object": object}) } func (d localDirectoryNode) GetMetadata(bucket, object string) (map[string]string, error) { - return d.getMetadata(bucket, object, "metadata.json") + m, err := d.getMetadata(bucket, object, "metadata.json") + return m, iodine.Error(err, map[string]string{"bucket": bucket, "object": object}) } func (d localDirectoryNode) GetDonutMetadata(bucket, object string) (map[string]string, error) { - return d.getMetadata(bucket, object, "donutMetadata.json") + m, err := d.getMetadata(bucket, object, "donutMetadata.json") + return m, iodine.Error(err, map[string]string{"bucket": bucket, "object": object}) } func (d localDirectoryNode) getMetadata(bucket, object, fileName string) (map[string]string, error) { + errParams := map[string]string{"bucket": bucket, "object": object, "file": fileName} file, err := os.Open(path.Join(d.root, bucket, object, fileName)) defer file.Close() if err != nil { - return nil, err + return nil, iodine.Error(err, errParams) } metadata := make(map[string]string) decoder := json.NewDecoder(file) if err := decoder.Decode(&metadata); err != nil { - return nil, err + return nil, iodine.Error(err, errParams) } return metadata, nil } func (d localDirectoryNode) ListObjects(bucketName string) ([]string, error) { + errParams := map[string]string{"bucket": bucketName} prefix := path.Join(d.root, bucketName) var objects []string if err := filepath.Walk(prefix, func(path string, info os.FileInfo, err error) error { if err != nil { - return err + return iodine.Error(err, errParams) } if !info.IsDir() && strings.HasSuffix(path, "data") { object := strings.TrimPrefix(path, prefix+"/") @@ -84,7 +92,7 @@ func (d localDirectoryNode) ListObjects(bucketName string) ([]string, error) { } return nil }); err != nil { - return nil, err + return nil, iodine.Error(err, errParams) } sort.Strings(objects) return objects, nil