2014-12-08 22:40:48 -05:00
|
|
|
package main
|
2014-12-09 06:32:31 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func put(c *cli.Context) {
|
|
|
|
config, err := parseInput(c)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2014-12-10 23:59:49 -05:00
|
|
|
objectPath := c.Args().Get(0)
|
|
|
|
var filePath string
|
|
|
|
switch len(c.Args()) {
|
|
|
|
case 1:
|
|
|
|
filePath = objectPath
|
|
|
|
case 2:
|
|
|
|
filePath = c.Args().Get(1)
|
|
|
|
default:
|
|
|
|
log.Fatal("Please specify a valid object name \n # erasure-demo put [OBJECTNAME] [FILENAME]")
|
2014-12-09 06:32:31 -05:00
|
|
|
}
|
|
|
|
inputFile, err := os.Open(filePath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
switch config.storageDriver {
|
|
|
|
case "fs":
|
|
|
|
{
|
2014-12-11 03:32:32 -05:00
|
|
|
if err := fsPut(config, c.Args().Get(0), inputFile); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "erasure":
|
|
|
|
{
|
|
|
|
if err := erasurePut(config, c.Args().Get(0), inputFile); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2014-12-09 06:32:31 -05:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
log.Fatal("Unknown driver")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|