mirror of https://github.com/minio/minio.git
Adding iodine to node_local
This commit is contained in:
parent
8cf66ede66
commit
5cdf2564a5
|
@ -8,6 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/minio-io/iodine"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
@ -18,13 +19,13 @@ type localDirectoryNode struct {
|
||||||
|
|
||||||
func (d localDirectoryNode) CreateBucket(bucket string) error {
|
func (d localDirectoryNode) CreateBucket(bucket string) error {
|
||||||
objectPath := path.Join(d.root, bucket)
|
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) {
|
func (d localDirectoryNode) GetBuckets() ([]string, error) {
|
||||||
files, err := ioutil.ReadDir(d.root)
|
files, err := ioutil.ReadDir(d.root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, iodine.Error(err, nil)
|
||||||
}
|
}
|
||||||
var results []string
|
var results []string
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
@ -36,46 +37,53 @@ func (d localDirectoryNode) GetBuckets() ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d localDirectoryNode) GetWriter(bucket, object string) (Writer, 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)
|
objectPath := path.Join(d.root, bucket, object)
|
||||||
err := os.MkdirAll(objectPath, 0700)
|
err := os.MkdirAll(objectPath, 0700)
|
||||||
if err != nil {
|
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) {
|
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) {
|
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) {
|
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) {
|
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))
|
file, err := os.Open(path.Join(d.root, bucket, object, fileName))
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, iodine.Error(err, errParams)
|
||||||
}
|
}
|
||||||
metadata := make(map[string]string)
|
metadata := make(map[string]string)
|
||||||
decoder := json.NewDecoder(file)
|
decoder := json.NewDecoder(file)
|
||||||
if err := decoder.Decode(&metadata); err != nil {
|
if err := decoder.Decode(&metadata); err != nil {
|
||||||
return nil, err
|
return nil, iodine.Error(err, errParams)
|
||||||
}
|
}
|
||||||
return metadata, nil
|
return metadata, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d localDirectoryNode) ListObjects(bucketName string) ([]string, error) {
|
func (d localDirectoryNode) ListObjects(bucketName string) ([]string, error) {
|
||||||
|
errParams := map[string]string{"bucket": bucketName}
|
||||||
prefix := path.Join(d.root, bucketName)
|
prefix := path.Join(d.root, bucketName)
|
||||||
var objects []string
|
var objects []string
|
||||||
if err := filepath.Walk(prefix, func(path string, info os.FileInfo, err error) error {
|
if err := filepath.Walk(prefix, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return iodine.Error(err, errParams)
|
||||||
}
|
}
|
||||||
if !info.IsDir() && strings.HasSuffix(path, "data") {
|
if !info.IsDir() && strings.HasSuffix(path, "data") {
|
||||||
object := strings.TrimPrefix(path, prefix+"/")
|
object := strings.TrimPrefix(path, prefix+"/")
|
||||||
|
@ -84,7 +92,7 @@ func (d localDirectoryNode) ListObjects(bucketName string) ([]string, error) {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, iodine.Error(err, errParams)
|
||||||
}
|
}
|
||||||
sort.Strings(objects)
|
sort.Strings(objects)
|
||||||
return objects, nil
|
return objects, nil
|
||||||
|
|
Loading…
Reference in New Issue