Merge pull request #99 from harshavardhana/pr_out_make_get_put_more_robust

master
Harshavardhana 10 years ago
commit 72ddb345a1
  1. 2
      Makefile
  2. 12
      cmd/erasure-demo/fs.go
  3. 28
      cmd/erasure-demo/get.go
  4. 20
      cmd/erasure-demo/main.go
  5. 32
      cmd/erasure-demo/put.go
  6. 19
      pkgs/storage/fsstorage/fs_storage.go
  7. 1
      pkgs/storage/storage.go

@ -32,7 +32,7 @@ build-split: build-strbyteconv
build-strbyteconv: build-strbyteconv:
@godep go test -race -coverprofile=cover.out github.com/minio-io/minio/pkgs/strbyteconv @godep go test -race -coverprofile=cover.out github.com/minio-io/minio/pkgs/strbyteconv
cover: build-erasure build-signify build-split build-crc32c cover: build-erasure build-signify build-split build-crc32c build-cpu build-sha1
@godep go test -race -coverprofile=cover.out github.com/minio-io/minio/pkgs/storage @godep go test -race -coverprofile=cover.out github.com/minio-io/minio/pkgs/storage
@godep go test -race -coverprofile=cover.out github.com/minio-io/minio/pkgs/gateway @godep go test -race -coverprofile=cover.out github.com/minio-io/minio/pkgs/gateway

@ -10,6 +10,18 @@ import (
"github.com/minio-io/minio/pkgs/storage/fsstorage" "github.com/minio-io/minio/pkgs/storage/fsstorage"
) )
func fsGetList(config inputConfig) (io.Reader, error) {
var objectStorage storage.ObjectStorage
rootDir := path.Join(config.rootDir, config.storageDriver)
objectStorage = fsstorage.FileSystemStorage{RootDir: rootDir}
objectlist, err := objectStorage.GetList()
if err != nil {
return nil, err
}
objectListBuffer := bytes.NewBuffer(objectlist)
return objectListBuffer, nil
}
func fsGet(config inputConfig, objectPath string) (io.Reader, error) { func fsGet(config inputConfig, objectPath string) (io.Reader, error) {
var objectStorage storage.ObjectStorage var objectStorage storage.ObjectStorage
rootDir := path.Join(config.rootDir, config.storageDriver) rootDir := path.Join(config.rootDir, config.storageDriver)

@ -14,39 +14,25 @@ func get(c *cli.Context) {
log.Fatal(err) log.Fatal(err)
} }
var objectReader io.Reader var objectReader io.Reader
objectName := c.Args().Get(0)
switch config.storageDriver { switch config.storageDriver {
case "fs": case "fs":
{ {
if objectReader, err = fsGet(config, c.Args().Get(0)); err != nil { if len(objectName) == 0 {
if objectReader, err = fsGetList(config); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} } else {
default: if objectReader, err = fsGet(config, objectName); err != nil {
{
log.Fatal("Unknown driver")
}
}
io.Copy(os.Stdout, objectReader)
}
func put(c *cli.Context) {
config, err := parseInput(c)
if err != nil {
log.Fatal(err) log.Fatal(err)
} }
filePath := c.Args().Get(1)
inputFile, err := os.Open(filePath)
if err != nil {
log.Fatal(err)
} }
switch config.storageDriver {
case "fs":
{
fsPut(config, c.Args().Get(0), inputFile)
} }
default: default:
{ {
log.Fatal("Unknown driver") log.Fatal("Unknown driver")
} }
} }
io.Copy(os.Stdout, objectReader)
} }

@ -176,5 +176,23 @@ func getMinioDir() string {
log.Fatal(err) log.Fatal(err)
} }
homePath := user.HomeDir homePath := user.HomeDir
return path.Join(homePath, ".minio") minioPath := path.Join(homePath, ".minio")
err = _initMinioDir(minioPath)
if err != nil {
log.Fatal(err)
}
return minioPath
}
func _initMinioDir(dirPath string) error {
_, err := os.Lstat(dirPath)
if err != nil {
log.Printf("%s not found, creating a new-one for the first time",
dirPath)
err = os.Mkdir(dirPath, 0700)
if err != nil {
return err
}
}
return nil
} }

@ -1 +1,33 @@
package main package main
import (
"log"
"os"
"github.com/codegangsta/cli"
)
func put(c *cli.Context) {
config, err := parseInput(c)
if err != nil {
log.Fatal(err)
}
filePath := c.Args().Get(0)
if len(filePath) == 0 {
log.Fatal("Please specify a valid object name \n # erasure-demo put <OBJECTNAME>")
}
inputFile, err := os.Open(filePath)
if err != nil {
log.Fatal(err)
}
switch config.storageDriver {
case "fs":
{
fsPut(config, c.Args().Get(0), inputFile)
}
default:
{
log.Fatal("Unknown driver")
}
}
}

@ -11,12 +11,27 @@ type FileSystemStorage struct {
RootDir string 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) { func (storage FileSystemStorage) Get(objectPath string) ([]byte, error) {
return ioutil.ReadFile(path.Join(storage.RootDir, objectPath)) return ioutil.ReadFile(path.Join(storage.RootDir, objectPath))
} }
func (storage FileSystemStorage) Put(objectPath string, object []byte) error { 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) return ioutil.WriteFile(path.Join(storage.RootDir, objectPath), object, 0600)
} }

@ -1,6 +1,7 @@
package storage package storage
type ObjectStorage interface { type ObjectStorage interface {
GetList() ([]byte, error)
Get(path string) ([]byte, error) Get(path string) ([]byte, error)
Put(path string, object []byte) error Put(path string, object []byte) error
} }

Loading…
Cancel
Save