mirror of
https://github.com/minio/minio.git
synced 2025-11-07 04:42:56 -05:00
Full restructure in accordance with
- pkg/{subsystem}/{package} style
- modify Makefile to reflect the new style,
consolidate various entries
- add a dummy ``main.go`` at top level
This commit is contained in:
1
cmd/crypto/.gitignore
vendored
1
cmd/crypto/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
crypto
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/minio/pkg/crypto/md5"
|
||||
"github.com/minio-io/minio/pkg/crypto/sha1"
|
||||
"github.com/minio-io/minio/pkg/crypto/sha256"
|
||||
"github.com/minio-io/minio/pkg/crypto/sha512"
|
||||
)
|
||||
|
||||
var Options = []cli.Command{
|
||||
Md5sum,
|
||||
Sha1sum,
|
||||
// Sha1sumFast, // TODO
|
||||
Sha256sum,
|
||||
Sha512sum,
|
||||
}
|
||||
|
||||
var Md5sum = cli.Command{
|
||||
Name: "md5sum",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doMd5sum,
|
||||
}
|
||||
|
||||
var Sha1sum = cli.Command{
|
||||
Name: "sha1sum",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doSha1sum,
|
||||
}
|
||||
|
||||
/* TODO
|
||||
var Sha1sumFast = cli.Command{
|
||||
Name: "sha1sum-fast",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doSha1sumFast,
|
||||
}
|
||||
*/
|
||||
|
||||
var Sha256sum = cli.Command{
|
||||
Name: "sha256sum",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doSha256sum,
|
||||
}
|
||||
|
||||
var Sha512sum = cli.Command{
|
||||
Name: "sha512sum",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doSha512sum,
|
||||
}
|
||||
|
||||
func doMd5sum(c *cli.Context) {
|
||||
hash, err := md5.Sum(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%x", hash)
|
||||
}
|
||||
|
||||
func doSha1sum(c *cli.Context) {
|
||||
hash, err := sha1.Sum(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%x", hash)
|
||||
}
|
||||
|
||||
/* TODO
|
||||
func doSha1sumFast(c *cli.Context) {
|
||||
buffer, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
hash, err := sha1.Sha1(buffer)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var bytesBuffer bytes.Buffer
|
||||
binary.Write(&bytesBuffer, binary.LittleEndian, hash)
|
||||
fmt.Printf("%x", bytesBuffer.Bytes())
|
||||
}
|
||||
*/
|
||||
|
||||
func doSha256sum(c *cli.Context) {
|
||||
hash, err := sha256.Sum(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%x", hash)
|
||||
}
|
||||
|
||||
func doSha512sum(c *cli.Context) {
|
||||
hash, err := sha512.Sum(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%x", hash)
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "crypto"
|
||||
app.Usage = "calculate cryptosum on a given stream"
|
||||
app.Commands = Options
|
||||
app.Run(os.Args)
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
% MINIO(1) Minio Manual
|
||||
% Minio community
|
||||
% December 2014
|
||||
# NAME
|
||||
crypto - calculate crypto sum on a stream
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
# DESCRIPTION
|
||||
```sh
|
||||
NAME:
|
||||
crypto - calculate cryptosum on a given stream
|
||||
|
||||
USAGE:
|
||||
crypto [global options] command [command options] [arguments...]
|
||||
|
||||
VERSION:
|
||||
0.0.0
|
||||
|
||||
COMMANDS:
|
||||
md5sum
|
||||
sha1sum
|
||||
sha256sum
|
||||
sha512sum
|
||||
help, h Shows a list of commands or help for one command
|
||||
|
||||
GLOBAL OPTIONS:
|
||||
--help, -h show help
|
||||
--version, -v print the version
|
||||
```
|
||||
# EXAMPLES
|
||||
|
||||
# AUTHORS
|
||||
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/go-patricia/patricia"
|
||||
"github.com/minio-io/minio/pkg/storage"
|
||||
)
|
||||
|
||||
var Options = []cli.Command{
|
||||
Add,
|
||||
Get,
|
||||
List,
|
||||
Remove,
|
||||
}
|
||||
|
||||
var Add = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Action: doAdd,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "objects.trie",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var Get = cli.Command{
|
||||
Name: "get",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Action: doGet,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "objects.trie",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var List = cli.Command{
|
||||
Name: "list",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "objects.trie",
|
||||
},
|
||||
},
|
||||
Action: doList,
|
||||
}
|
||||
|
||||
var Remove = cli.Command{
|
||||
Name: "remove",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Action: doRemove,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "objects.trie",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func doAdd(c *cli.Context) {
|
||||
// register patricia for gob
|
||||
registerPatriciaWithGob()
|
||||
|
||||
trie, err := readTrie(c.String("path"))
|
||||
if err != nil {
|
||||
log.Panic("err: ", trie, err)
|
||||
}
|
||||
log.Println("trie: ", trie, err)
|
||||
|
||||
var object storage.ObjectDescription
|
||||
object.Name = c.Args().Get(1)
|
||||
object.Md5sum = "md5sum"
|
||||
object.Murmur3 = "murmur3"
|
||||
|
||||
key := []byte(c.Args().Get(0))
|
||||
|
||||
trie.Insert(key, object)
|
||||
log.Println("newTrie:", trie)
|
||||
saveTrie(c.String("path"), trie)
|
||||
}
|
||||
|
||||
func doGet(c *cli.Context) {
|
||||
registerPatriciaWithGob()
|
||||
|
||||
trie, err := readTrie(c.String("path"))
|
||||
if err != nil {
|
||||
log.Panic("err: ", trie, err)
|
||||
}
|
||||
description := trie.Get([]byte(c.Args().Get(0)))
|
||||
log.Println(trie)
|
||||
log.Println(description)
|
||||
|
||||
}
|
||||
func doList(c *cli.Context) {
|
||||
registerPatriciaWithGob()
|
||||
trie, err := readTrie(c.String("path"))
|
||||
if err != nil {
|
||||
log.Panic("err: ", trie, err)
|
||||
}
|
||||
prefix := patricia.Prefix(c.Args().Get(0))
|
||||
trie.VisitSubtree(prefix, func(prefix patricia.Prefix, item patricia.Item) error {
|
||||
fmt.Println(string(prefix))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func doRemove(c *cli.Context) {
|
||||
registerPatriciaWithGob()
|
||||
trie, err := readTrie(c.String("path"))
|
||||
if err != nil {
|
||||
log.Panic("err: ", trie, err)
|
||||
}
|
||||
prefix := patricia.Prefix(c.Args().Get(0))
|
||||
trie.Delete(prefix)
|
||||
saveTrie(c.String("path"), trie)
|
||||
}
|
||||
|
||||
func readTrie(path string) (*patricia.Trie, error) {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return patricia.NewTrie(), nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
decoder := gob.NewDecoder(file)
|
||||
trie := patricia.NewTrie()
|
||||
if err = decoder.Decode(trie); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return trie, nil
|
||||
}
|
||||
|
||||
func saveTrie(path string, trie *patricia.Trie) error {
|
||||
// file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC, 0600)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
var buffer bytes.Buffer
|
||||
encoder := gob.NewEncoder(&buffer)
|
||||
if err := encoder.Encode(trie); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
log.Println("marshalled trie:", buffer.Bytes())
|
||||
err := ioutil.WriteFile(path, buffer.Bytes(), 0600)
|
||||
return err
|
||||
}
|
||||
|
||||
func registerPatriciaWithGob() {
|
||||
gob.Register(storage.ObjectDescription{})
|
||||
gob.Register(&patricia.SparseChildList{})
|
||||
gob.Register(&patricia.DenseChildList{})
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "index"
|
||||
app.Usage = ""
|
||||
app.Commands = Options
|
||||
app.Author = "Minio"
|
||||
app.Run(os.Args)
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
|
||||
% MINIO(1) Minio Manual
|
||||
% Minio community
|
||||
% January 2015
|
||||
# NAME
|
||||
index -
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
# EXAMPLES
|
||||
|
||||
# AUTHORS
|
||||
@@ -1,43 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func add(c *cli.Context) {
|
||||
config, err := parseInput(c)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var filePath, objectName string
|
||||
switch len(c.Args()) {
|
||||
case 1:
|
||||
objectName = path.Base(c.Args().Get(0))
|
||||
filePath = c.Args().Get(0)
|
||||
case 2:
|
||||
objectName = c.Args().Get(0)
|
||||
filePath = c.Args().Get(1)
|
||||
default:
|
||||
log.Fatal("Please specify a valid object name \n # erasure-demo put [OBJECTNAME] [FILENAME]")
|
||||
}
|
||||
inputFile, err := os.Open(filePath)
|
||||
defer inputFile.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Staging parity
|
||||
stagingConfig := config
|
||||
stagingConfig.k = 2
|
||||
stagingConfig.m = 1
|
||||
stagingConfig.rootDir = config.stagingDir
|
||||
|
||||
if err := erasurePut(stagingConfig, objectName, inputFile); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func cleanupStagingDir(stagingDir string) {
|
||||
filelist, err := ioutil.ReadDir(stagingDir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, file := range filelist {
|
||||
_file := path.Join(stagingDir, file.Name())
|
||||
if err := os.Remove(_file); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func commit(c *cli.Context) {
|
||||
config, err := parseInput(c)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var objectName string
|
||||
switch len(c.Args()) {
|
||||
case 1:
|
||||
objectName = c.Args().Get(0)
|
||||
default:
|
||||
log.Fatal("Please specify a valid object name \n # erasure-demo encode [OBJECTNAME]")
|
||||
}
|
||||
|
||||
// Get from staging area
|
||||
stagingConfig := config
|
||||
stagingConfig.k = 2
|
||||
stagingConfig.m = 1
|
||||
stagingConfig.rootDir = config.stagingDir
|
||||
reader, err := erasureGet(stagingConfig, objectName)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Increase parity to user defined or default 10,6
|
||||
err = erasurePut(config, objectName, reader)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Cleanup stagingDir
|
||||
cleanupStagingDir(config.stagingDir)
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/minio/pkg/strbyteconv"
|
||||
)
|
||||
|
||||
// config representing cli input
|
||||
type inputConfig struct {
|
||||
k int
|
||||
m int
|
||||
blockSize uint64
|
||||
rootDir string
|
||||
stagingDir string
|
||||
}
|
||||
|
||||
// parses input and returns an inputConfig with parsed input
|
||||
func parseInput(c *cli.Context) (inputConfig, error) {
|
||||
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")
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var rootDir string
|
||||
if c.String("root") != "" {
|
||||
rootDir = c.String("root")
|
||||
}
|
||||
|
||||
var stagingDir string
|
||||
if c.String("staging") != "" {
|
||||
stagingDir = c.String("staging")
|
||||
}
|
||||
|
||||
config := inputConfig{
|
||||
k: k,
|
||||
m: m,
|
||||
blockSize: blockSize,
|
||||
rootDir: rootDir,
|
||||
stagingDir: stagingDir,
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func getObjectdir(basename string) string {
|
||||
user, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
homePath := user.HomeDir
|
||||
minioPath := path.Join(homePath, basename)
|
||||
err = _initDir(minioPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return minioPath
|
||||
}
|
||||
|
||||
func _initDir(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.MkdirAll(dirPath, 0700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/minio-io/minio/pkg/storage"
|
||||
es "github.com/minio-io/minio/pkg/storage/encodedstorage"
|
||||
)
|
||||
|
||||
func erasureGetList(config inputConfig, objectPath string) (io.Reader, error) {
|
||||
var objectStorage storage.ObjectStorage
|
||||
objectStorage, err := es.NewStorage(config.rootDir, config.k, config.m, config.blockSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objectDescList, err := objectStorage.List(objectPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var objectDescListBytes []byte
|
||||
if objectDescListBytes, err = json.Marshal(objectDescList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objectDescListBuffer := bytes.NewBuffer(objectDescListBytes)
|
||||
|
||||
return objectDescListBuffer, nil
|
||||
}
|
||||
|
||||
func erasureGet(config inputConfig, objectPath string) (io.Reader, error) {
|
||||
var objectStorage storage.ObjectStorage
|
||||
objectStorage, err := es.NewStorage(config.rootDir, config.k, config.m, config.blockSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
object, err := objectStorage.Get(objectPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return object, nil
|
||||
}
|
||||
|
||||
func erasurePut(config inputConfig, objectPath string, reader io.Reader) error {
|
||||
var err error
|
||||
if err := os.MkdirAll(config.rootDir, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
var objectStorage storage.ObjectStorage
|
||||
if objectStorage, err = es.NewStorage(config.rootDir, config.k, config.m, config.blockSize); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = objectStorage.Put(objectPath, reader); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func get(c *cli.Context) {
|
||||
config, err := parseInput(c)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var objectName string
|
||||
var objectReader io.Reader
|
||||
switch len(c.Args()) {
|
||||
case 1:
|
||||
objectName = c.Args().Get(0)
|
||||
default:
|
||||
log.Fatal("Please specify a valid object name \n # erasure-demo get [OBJECTNAME]")
|
||||
}
|
||||
|
||||
getConfig := config
|
||||
getConfig.k = 10
|
||||
getConfig.m = 6
|
||||
if objectReader, err = erasureGet(getConfig, objectName); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
io.Copy(os.Stdout, objectReader)
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package main
|
||||
@@ -1,24 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func list(c *cli.Context) {
|
||||
config, err := parseInput(c)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
config.k = 10
|
||||
config.m = 6
|
||||
reader, err := erasureGetList(config, "")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
io.Copy(os.Stdout, reader)
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "minio"
|
||||
app.Usage = "minio - object storage"
|
||||
app.Commands = []cli.Command{
|
||||
{
|
||||
Name: "commit",
|
||||
Usage: "provide higher protection for uploaded object",
|
||||
Action: commit,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "root",
|
||||
Value: getObjectdir(".minio/erasure"),
|
||||
Usage: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "staging",
|
||||
Value: getObjectdir(".minio/staging"),
|
||||
Usage: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "protection-level",
|
||||
Value: "10,6",
|
||||
Usage: "data,parity",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "block-size",
|
||||
Value: "1M",
|
||||
Usage: "Size of blocks. Examples: 1K, 1M, full",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "get",
|
||||
Usage: "get an object",
|
||||
Action: get,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "root",
|
||||
Value: getObjectdir(".minio/erasure"),
|
||||
Usage: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "block-size",
|
||||
Value: "1M",
|
||||
Usage: "Size of blocks. Examples: 1K, 1M, full",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "add",
|
||||
Usage: "add an object",
|
||||
Action: add,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "staging",
|
||||
Value: getObjectdir(".minio/staging"),
|
||||
Usage: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "block-size",
|
||||
Value: "1M",
|
||||
Usage: "Size of blocks. Examples: 1K, 1M, full",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "list",
|
||||
Usage: "list objects",
|
||||
Action: list,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "root",
|
||||
Value: getObjectdir(".minio/erasure"),
|
||||
Usage: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
app.Run(os.Args)
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package main
|
||||
1
cmd/new-cmd/.gitignore
vendored
1
cmd/new-cmd/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
new-cmd
|
||||
@@ -1,25 +0,0 @@
|
||||
## Introduction
|
||||
|
||||
`new-cmd` is a stub builder for new commands,options on top of [codegangsta/cli](https://github.com/codegangsta/cli),
|
||||
|
||||
Idea behind providing a simple tool for rapid prototyping and encouraging new contributors to the project
|
||||
|
||||
## Usage
|
||||
|
||||
You just need to set its command name and options:
|
||||
|
||||
```bash
|
||||
$ new-cmd --options option1,option2,option3 --usage "This command is best" [commandname]
|
||||
```
|
||||
|
||||
Generates three files [commandname].go, [commandname]-options.go, [commandname].md respectively
|
||||
|
||||
## Example
|
||||
|
||||
If you want to start to building `bucket` command which has options `get`, `put`, `list`:
|
||||
|
||||
```bash
|
||||
$ new-cmd --options get,put,list --usage "Bucket operations" bucket
|
||||
$ ls bucket/
|
||||
bucket-options.go bucket.go bucket.md
|
||||
```
|
||||
@@ -1,89 +0,0 @@
|
||||
// this code is from gofmt, modified for our internal usage - http://golang.org/src/cmd/gofmt/gofmt.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/printer"
|
||||
"go/token"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error {
|
||||
if in == nil {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
in = f
|
||||
}
|
||||
|
||||
src, err := ioutil.ReadAll(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileSet := token.NewFileSet()
|
||||
file, err := parser.ParseFile(fileSet, filename, src, parser.ParseComments)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ast.SortImports(fileSet, file)
|
||||
|
||||
var buf bytes.Buffer
|
||||
tabWidth := 8
|
||||
printerMode := printer.UseSpaces | printer.TabIndent
|
||||
err = (&printer.Config{Mode: printerMode, Tabwidth: tabWidth}).Fprint(&buf, fileSet, file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res := buf.Bytes()
|
||||
if !bytes.Equal(src, res) {
|
||||
err = ioutil.WriteFile(filename, res, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isGofile(f os.FileInfo) bool {
|
||||
name := f.Name()
|
||||
return !f.IsDir() && !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go")
|
||||
}
|
||||
|
||||
func visitFile(pathName string, f os.FileInfo, err error) error {
|
||||
|
||||
if err == nil && isGofile(f) {
|
||||
err = processFile(pathName, nil, os.Stdout, false)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func walkDir(pathName string) {
|
||||
filepath.Walk(pathName, visitFile)
|
||||
}
|
||||
|
||||
func GoFormat(pathName string) error {
|
||||
dir, err := os.Stat(pathName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if dir.IsDir() {
|
||||
walkDir(pathName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/minio/pkg/utils"
|
||||
)
|
||||
|
||||
func parseInput(c *cli.Context) {
|
||||
var commandName string
|
||||
switch len(c.Args()) {
|
||||
case 1:
|
||||
commandName = c.Args()[0]
|
||||
default:
|
||||
log.Fatal("command name must not be blank\n")
|
||||
}
|
||||
|
||||
var inputOptions []string
|
||||
if c.String("options") != "" {
|
||||
inputOptions = strings.Split(c.String("options"), ",")
|
||||
}
|
||||
|
||||
if inputOptions[0] == "" {
|
||||
log.Fatal("options cannot be empty with a command name")
|
||||
}
|
||||
|
||||
var commandUsage string
|
||||
if c.String("usage") != "" {
|
||||
commandUsage = c.String("usage")
|
||||
}
|
||||
|
||||
var mainObject = template.Must(template.New("main").Parse(commandTemplate))
|
||||
var optionsObject = template.Must(template.New("options").Parse(optionsTemplate))
|
||||
var readmeObject = template.Must(template.New("readme").Parse(readmeTemplate))
|
||||
|
||||
err := os.Mkdir(commandName, 0755)
|
||||
utils.Assert(err)
|
||||
|
||||
command := initCommand(commandName, commandUsage, inputOptions)
|
||||
|
||||
optionsGo := source{
|
||||
Name: commandName + "-options.go",
|
||||
TempLate: *optionsObject,
|
||||
}
|
||||
|
||||
readmeMd := source{
|
||||
Name: commandName + ".md",
|
||||
TempLate: *readmeObject,
|
||||
}
|
||||
|
||||
mainGo := source{
|
||||
Name: commandName + ".go",
|
||||
TempLate: *mainObject,
|
||||
}
|
||||
|
||||
err = readmeMd.get(commandName, command)
|
||||
utils.Assert(err)
|
||||
|
||||
mainGo.get(commandName, command)
|
||||
utils.Assert(err)
|
||||
|
||||
optionsGo.get(commandName, command)
|
||||
|
||||
err = GoFormat(commandName)
|
||||
utils.Assert(err)
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/minio/pkg/utils"
|
||||
)
|
||||
|
||||
type source struct {
|
||||
Name string
|
||||
TempLate template.Template
|
||||
}
|
||||
|
||||
type option struct {
|
||||
Name string
|
||||
Definename string
|
||||
Functionname string
|
||||
}
|
||||
|
||||
type command struct {
|
||||
Name string
|
||||
Usage string
|
||||
Month string
|
||||
Year int
|
||||
Options []option
|
||||
}
|
||||
|
||||
func (f source) get(commandName string, definition command) error {
|
||||
wr, err := os.Create(path.Join(commandName, f.Name))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer wr.Close()
|
||||
return f.TempLate.Execute(wr, definition)
|
||||
}
|
||||
|
||||
func initCommand(commandname, usage string, inputOptions []string) command {
|
||||
year, month, _ := time.Now().Date()
|
||||
return command{
|
||||
Name: commandname,
|
||||
Usage: usage,
|
||||
Month: month.String(),
|
||||
Year: year,
|
||||
Options: initOptions(inputOptions),
|
||||
}
|
||||
}
|
||||
|
||||
func initOptions(inputOptions []string) []option {
|
||||
var options []option
|
||||
|
||||
if inputOptions[0] == "" {
|
||||
return options
|
||||
}
|
||||
|
||||
for _, name := range inputOptions {
|
||||
option := option{
|
||||
Name: name,
|
||||
Definename: utils.FirstUpper(name),
|
||||
Functionname: "do" + utils.FirstUpper(name),
|
||||
}
|
||||
options = append(options, option)
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "new-cmd"
|
||||
app.Usage = "Is a stub builder for new commands, options"
|
||||
var flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "options",
|
||||
Value: "",
|
||||
Usage: "Command-separated list of options to build",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "usage",
|
||||
Value: "",
|
||||
Usage: "A one liner explaining the new command being built",
|
||||
},
|
||||
}
|
||||
app.Flags = flags
|
||||
app.Action = parseInput
|
||||
app.Author = "Minio"
|
||||
app.Run(os.Args)
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package main
|
||||
|
||||
const (
|
||||
commandTemplate = `
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "{{.Name}}"
|
||||
app.Usage = "{{.Usage}}"
|
||||
app.Commands = Options
|
||||
app.Author = "Minio"
|
||||
app.Run(os.Args)
|
||||
}
|
||||
`
|
||||
optionsTemplate = `
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
var Options = []cli.Command{
|
||||
{{range .Options}}{{.Definename}},
|
||||
{{end}}
|
||||
}
|
||||
|
||||
{{range .Options}}
|
||||
var {{.Definename}} = cli.Command{
|
||||
Name: "{{.Name}}",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Action: {{.Functionname}},
|
||||
}
|
||||
{{end}}
|
||||
|
||||
{{range .Options}}
|
||||
func {{.Functionname}}(c *cli.Context) {
|
||||
}
|
||||
{{end}}
|
||||
`
|
||||
readmeTemplate = `
|
||||
% MINIO(1) Minio Manual
|
||||
% Minio community
|
||||
% {{.Month}} {{.Year}}
|
||||
# NAME
|
||||
{{.Name}} - {{.Usage}}
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
# EXAMPLES
|
||||
|
||||
# AUTHORS
|
||||
`
|
||||
)
|
||||
1
cmd/split/.gitignore
vendored
1
cmd/split/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
split
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/minio/pkg/split"
|
||||
"github.com/minio-io/minio/pkg/strbyteconv"
|
||||
)
|
||||
|
||||
var Options = []cli.Command{
|
||||
Split,
|
||||
Merge,
|
||||
}
|
||||
|
||||
var Split = cli.Command{
|
||||
Name: "split",
|
||||
Usage: "Describes how large each split should be",
|
||||
Description: "",
|
||||
Action: doFileSplit,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "size,s",
|
||||
Value: "2M",
|
||||
Usage: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var Merge = cli.Command{
|
||||
Name: "merge",
|
||||
Usage: "Describes how large each split should be",
|
||||
Description: "",
|
||||
Action: doFileMerge,
|
||||
}
|
||||
|
||||
func doFileSplit(c *cli.Context) {
|
||||
chunkSize, err := strbyteconv.StringToBytes(c.String("size"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = split.SplitFileWithPrefix(c.Args().Get(0), chunkSize, c.Args().Get(1))
|
||||
if err != nil {
|
||||
// TODO cleanup?
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func doFileMerge(c *cli.Context) {
|
||||
prefix := c.Args().Get(0)
|
||||
output := c.Args().Get(1)
|
||||
prefix = path.Clean(prefix)
|
||||
log.Println(path.Dir(prefix), path.Base(prefix))
|
||||
reader := split.JoinFiles(path.Dir(prefix), path.Base(prefix))
|
||||
file, err := os.OpenFile(output, os.O_WRONLY|os.O_CREATE, 0600)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer file.Close()
|
||||
io.Copy(file, reader)
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "split"
|
||||
app.Usage = ""
|
||||
app.Commands = Options
|
||||
app.Author = "Minio"
|
||||
app.Run(os.Args)
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
|
||||
% MINIO(1) Minio Manual
|
||||
% Minio community
|
||||
% January 2015
|
||||
# NAME
|
||||
split -
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
# EXAMPLES
|
||||
|
||||
# AUTHORS
|
||||
Reference in New Issue
Block a user