mirror of
https://github.com/minio/minio.git
synced 2025-12-07 16:22:33 -05:00
Make get/put more robust
- init folder if not present already in 'get()' call
- put.go was referencing wrong args - fix it
- if no OBJECTNAME is specified during 'get' - grab a
list of files under "~/.minio"
- Provide new API GetList() for ObjectStorage struct
This commit is contained in:
@@ -11,12 +11,27 @@ type FileSystemStorage struct {
|
||||
RootDir string
|
||||
}
|
||||
|
||||
func (storage FileSystemStorage) GetList() ([]byte, error) {
|
||||
fileInfos, err := ioutil.ReadDir(storage.RootDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var list []byte
|
||||
for _, fi := range fileInfos {
|
||||
list = append(list, "{"+fi.Name()+"}\n"...)
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (storage FileSystemStorage) Get(objectPath string) ([]byte, error) {
|
||||
return ioutil.ReadFile(path.Join(storage.RootDir, objectPath))
|
||||
|
||||
}
|
||||
|
||||
func (storage FileSystemStorage) Put(objectPath string, object []byte) error {
|
||||
os.MkdirAll(filepath.Dir(path.Join(storage.RootDir, objectPath)), 0700)
|
||||
err := os.MkdirAll(filepath.Dir(path.Join(storage.RootDir, objectPath)), 0700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(path.Join(storage.RootDir, objectPath), object, 0600)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package storage
|
||||
|
||||
type ObjectStorage interface {
|
||||
GetList() ([]byte, error)
|
||||
Get(path string) ([]byte, error)
|
||||
Put(path string, object []byte) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user