Adding extremely simple fs based get and put in erasure-demo

This commit is contained in:
Frederick F. Kautz IV
2014-12-08 19:40:48 -08:00
parent c2917f0d64
commit d1ebf935da
4 changed files with 183 additions and 25 deletions
+90 -25
View File
@@ -2,7 +2,10 @@ package main
import (
"errors"
"log"
"os"
"os/user"
"path"
"strconv"
"strings"
@@ -54,17 +57,53 @@ func main() {
},
},
},
{
Name: "get",
Usage: "get an object",
Action: get,
Flags: []cli.Flag{
cli.StringFlag{
Name: "root",
Value: getMinioDir(),
Usage: "",
},
cli.StringFlag{
Name: "driver",
Value: "fs",
Usage: "fs",
},
},
},
{
Name: "put",
Usage: "put an object",
Action: put,
Flags: []cli.Flag{
cli.StringFlag{
Name: "root",
Value: getMinioDir(),
Usage: "",
},
cli.StringFlag{
Name: "driver",
Value: "fs",
Usage: "fs",
},
},
},
}
app.Run(os.Args)
}
// config representing cli input
type inputConfig struct {
input string
output string
k int
m int
blockSize uint64
input string
output string
k int
m int
blockSize uint64
rootDir string
storageDriver string
}
// parses input and returns an inputConfig with parsed input
@@ -78,26 +117,30 @@ func parseInput(c *cli.Context) (inputConfig, error) {
outputFilePath = c.String("output")
}
protectionLevel := c.String("protection-level")
protectionLevelSplit := strings.Split(protectionLevel, ",")
if len(protectionLevelSplit) != 2 {
return inputConfig{}, errors.New("Malformed input for protection-level")
}
var k, m int
if c.String("protection-level") != "" {
protectionLevel := c.String("protection-level")
protectionLevelSplit := strings.Split(protectionLevel, ",")
if len(protectionLevelSplit) != 2 {
return inputConfig{}, errors.New("Malformed input for protection-level")
}
k, err := strconv.Atoi(protectionLevelSplit[0])
if err != nil {
return inputConfig{}, err
}
m, err := strconv.Atoi(protectionLevelSplit[1])
if err != nil {
return inputConfig{}, err
var err error
k, err = strconv.Atoi(protectionLevelSplit[0])
if err != nil {
return inputConfig{}, err
}
m, err = strconv.Atoi(protectionLevelSplit[1])
if err != nil {
return inputConfig{}, err
}
}
var blockSize uint64
blockSize = 0
if c.String("block-size") != "" {
if c.String("block-size") != "full" {
var err error
blockSize, err = strbyteconv.StringToBytes(c.String("block-size"))
if err != nil {
return inputConfig{}, err
@@ -105,11 +148,33 @@ func parseInput(c *cli.Context) (inputConfig, error) {
}
}
return inputConfig{
input: inputFilePath,
output: outputFilePath,
k: k,
m: m,
blockSize: blockSize,
}, nil
var rootDir string
if c.String("root") != "" {
rootDir = c.String("root")
}
var storageDriver string
if c.String("driver") != "" {
storageDriver = c.String("driver")
}
config := inputConfig{
input: inputFilePath,
output: outputFilePath,
k: k,
m: m,
blockSize: blockSize,
rootDir: rootDir,
storageDriver: storageDriver,
}
return config, nil
}
func getMinioDir() string {
user, err := user.Current()
if err != nil {
log.Fatal(err)
}
homePath := user.HomeDir
return path.Join(homePath, ".minio")
}