Implement simple encoded storage in gateway

This commit is contained in:
Harshavardhana
2014-12-11 16:49:35 -08:00
parent a56710e318
commit e15edbf393
4 changed files with 64 additions and 22 deletions

View File

@@ -10,11 +10,18 @@ import (
"github.com/minio-io/minio/pkgs/storage"
)
type FileSystemStorage struct {
type fileSystemStorage struct {
RootDir string
}
func (fsStorage FileSystemStorage) List(listPath string) ([]storage.ObjectDescription, error) {
func NewStorage(rootDir string) (storage.ObjectStorage, error) {
newStorage := fileSystemStorage{
RootDir: rootDir,
}
return &newStorage, nil
}
func (fsStorage *fileSystemStorage) List(listPath string) ([]storage.ObjectDescription, error) {
fileInfos, err := ioutil.ReadDir(path.Join(fsStorage.RootDir, listPath))
if err != nil {
return nil, err
@@ -33,11 +40,11 @@ func (fsStorage FileSystemStorage) List(listPath string) ([]storage.ObjectDescri
return descriptions, nil
}
func (storage FileSystemStorage) Get(objectPath string) (io.Reader, error) {
func (storage *fileSystemStorage) Get(objectPath string) (io.Reader, error) {
return os.Open(path.Join(storage.RootDir, objectPath))
}
func (storage FileSystemStorage) Put(objectPath string, object io.Reader) error {
func (storage *fileSystemStorage) Put(objectPath string, object io.Reader) error {
err := os.MkdirAll(filepath.Dir(path.Join(storage.RootDir, objectPath)), 0700)
if err != nil {
return err

View File

@@ -10,9 +10,9 @@ import (
. "gopkg.in/check.v1"
)
type FileSystemStorageSuite struct{}
type fileSystemStorageSuite struct{}
var _ = Suite(&FileSystemStorageSuite{})
var _ = Suite(&fileSystemStorageSuite{})
func Test(t *testing.T) { TestingT(t) }
@@ -20,15 +20,13 @@ func makeTempTestDir() (string, error) {
return ioutil.TempDir("/tmp", "minio-test-")
}
func (s *FileSystemStorageSuite) TestFileStoragePutAtRootPath(c *C) {
func (s *fileSystemStorageSuite) TestfileStoragePutAtRootPath(c *C) {
rootDir, err := makeTempTestDir()
c.Assert(err, IsNil)
defer os.RemoveAll(rootDir)
var objectStorage storage.ObjectStorage
objectStorage = FileSystemStorage{
RootDir: rootDir,
}
objectStorage, _ = NewStorage(rootDir)
objectBuffer := bytes.NewBuffer([]byte("object1"))
objectStorage.Put("path1", objectBuffer)
@@ -44,15 +42,13 @@ func (s *FileSystemStorageSuite) TestFileStoragePutAtRootPath(c *C) {
c.Assert(objectList[0].Path, Equals, "path1")
}
func (s *FileSystemStorageSuite) TestFileStoragePutDirPath(c *C) {
func (s *fileSystemStorageSuite) TestfileStoragePutDirPath(c *C) {
rootDir, err := makeTempTestDir()
c.Assert(err, IsNil)
defer os.RemoveAll(rootDir)
var objectStorage storage.ObjectStorage
objectStorage = FileSystemStorage{
RootDir: rootDir,
}
objectStorage, _ = NewStorage(rootDir)
objectBuffer1 := bytes.NewBuffer([]byte("object1"))
objectStorage.Put("path1/path2/path3", objectBuffer1)