mirror of
https://github.com/pgsty/minio.git
synced 2026-08-09 07:43:29 +03:00
Refactoring input parsing for erasure-demo
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/minio/pkgs/erasure"
|
||||
@@ -18,39 +17,21 @@ func decode(c *cli.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// get input path
|
||||
inputFilePath := c.Args().Get(0)
|
||||
|
||||
// get output path
|
||||
outputFilePath := inputFilePath
|
||||
if c.String("output") != "" {
|
||||
outputFilePath = c.String("output")
|
||||
}
|
||||
|
||||
protectionLevel := c.String("protection-level")
|
||||
protectionLevelSplit := strings.Split(protectionLevel, ",")
|
||||
if len(protectionLevelSplit) != 2 {
|
||||
log.Fatal("Malformed input for protection-level")
|
||||
}
|
||||
|
||||
k, err := strconv.Atoi(protectionLevelSplit[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
m, err := strconv.Atoi(protectionLevelSplit[1])
|
||||
config, err := parseInput(c)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
k := config.k
|
||||
m := config.m
|
||||
// get chunks
|
||||
chunks := make([][]byte, k+m)
|
||||
for i := 0; i < k+m; i++ {
|
||||
chunks[i], _ = ioutil.ReadFile(inputFilePath + "." + strconv.Itoa(i))
|
||||
chunks[i], _ = ioutil.ReadFile(config.input + "." + strconv.Itoa(i))
|
||||
}
|
||||
|
||||
// get length
|
||||
lengthBytes, err := ioutil.ReadFile(inputFilePath + ".length")
|
||||
lengthBytes, err := ioutil.ReadFile(config.input + ".length")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -70,8 +51,8 @@ func decode(c *cli.Context) {
|
||||
}
|
||||
|
||||
// write decode data out
|
||||
if _, err := os.Stat(outputFilePath); os.IsNotExist(err) {
|
||||
ioutil.WriteFile(outputFilePath, decodedData, 0600)
|
||||
if _, err := os.Stat(config.output); os.IsNotExist(err) {
|
||||
ioutil.WriteFile(config.output, decodedData, 0600)
|
||||
} else {
|
||||
log.Fatal("Output file already exists")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user