Merge pull request #966 from harshavardhana/pr_out_fix_signature_issues_in_turn_fixing_mirror_issues

Fix signature issues, in-turn fixing mirror issues
This commit is contained in:
Harshavardhana
2015-08-04 00:15:32 -07:00
29 changed files with 142 additions and 86 deletions
+6 -6
View File
@@ -7,7 +7,7 @@
"Deps": [
{
"ImportPath": "github.com/dustin/go-humanize",
"Rev": "00897f070f09f194c26d65afae734ba4c32404e8"
"Rev": "c128122e0b9b93799aef8181a537e5d8fd7081d6"
},
{
"ImportPath": "github.com/fatih/color",
@@ -29,13 +29,13 @@
},
{
"ImportPath": "github.com/minio/minio-go",
"Comment": "v0.2.0-12-g20db439",
"Rev": "20db439bc6671562eeff32d4cc3381eb7e824671"
"Comment": "v0.2.0-16-gd4b3d1e",
"Rev": "d4b3d1ecfb717775481044e72cc10cc0d534dc0c"
},
{
"ImportPath": "github.com/minio/minio/pkg/probe",
"Comment": "release-1434511043-296-g7f13095",
"Rev": "7f1309526056653a8e07277b3e39bfc49766363a"
"Comment": "release-1434511043-300-g28d9565",
"Rev": "28d9565400d68ae1cd79b81075823f10775e6230"
},
{
"ImportPath": "github.com/minio/pb",
@@ -56,7 +56,7 @@
},
{
"ImportPath": "gopkg.in/check.v1",
"Rev": "11d3bc7aa68e238947792f30573146a3231fc0f1"
"Rev": "b3d3430320d4260e5fea99841af984b3badcea63"
}
]
}
+1 -1
View File
@@ -115,7 +115,7 @@ func humanateBigBytes(s, base *big.Int, sizes []string) string {
//
// BigBytes(82854982) -> 83MB
func BigBytes(s *big.Int) string {
sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
return humanateBigBytes(s, bigSIExp, sizes)
}
+2 -2
View File
@@ -86,8 +86,8 @@ func TestBigBytes(t *testing.T) {
{"bytes(803)", bbyte(803), "803B"},
{"bytes(999)", bbyte(999), "999B"},
{"bytes(1024)", bbyte(1024), "1.0KB"},
{"bytes(1MB - 1)", bbyte(MByte - Byte), "1000KB"},
{"bytes(1024)", bbyte(1024), "1.0kB"},
{"bytes(1MB - 1)", bbyte(MByte - Byte), "1000kB"},
{"bytes(1MB)", bbyte(1024 * 1024), "1.0MB"},
{"bytes(1GB - 1K)", bbyte(GByte - KByte), "1000MB"},
+1 -1
View File
@@ -86,7 +86,7 @@ func humanateBytes(s uint64, base float64, sizes []string) string {
//
// Bytes(82854982) -> 83MB
func Bytes(s uint64) string {
sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"}
return humanateBytes(s, 1000, sizes)
}
+3 -3
View File
@@ -80,9 +80,9 @@ func TestBytes(t *testing.T) {
{"bytes(803)", Bytes(803), "803B"},
{"bytes(999)", Bytes(999), "999B"},
{"bytes(1024)", Bytes(1024), "1.0KB"},
{"bytes(9999)", Bytes(9999), "10KB"},
{"bytes(1MB - 1)", Bytes(MByte - Byte), "1000KB"},
{"bytes(1024)", Bytes(1024), "1.0kB"},
{"bytes(9999)", Bytes(9999), "10kB"},
{"bytes(1MB - 1)", Bytes(MByte - Byte), "1000kB"},
{"bytes(1MB)", Bytes(1024 * 1024), "1.0MB"},
{"bytes(1GB - 1K)", Bytes(GByte - KByte), "1000MB"},
+1 -1
View File
@@ -18,7 +18,7 @@ func Comma(v int64) string {
v = 0 - v
}
parts := []string{"", "", "", "", "", "", "", ""}
parts := []string{"", "", "", "", "", "", ""}
j := len(parts) - 1
for v > 999 {
+1 -1
View File
@@ -69,7 +69,7 @@ func urlEncodeName(name string) (string, error) {
continue
}
switch s {
case '-', '_', '.', '~', '/': // §2.3 Unreserved characters (mark)
case '-', '_', '.', '~', '/', '+': // §2.3 Unreserved characters (mark)
encodedName = encodedName + string(s)
continue
default:
+18
View File
@@ -82,6 +82,23 @@ var ignoredHeaders = map[string]bool{
"User-Agent": true,
}
func path2BucketAndObject(path string) (bucketName, objectName string) {
pathSplits := strings.SplitN(path, "?", 2)
splits := strings.SplitN(pathSplits[0], separator, 3)
switch len(splits) {
case 0, 1:
bucketName = ""
objectName = ""
case 2:
bucketName = splits[1]
objectName = ""
case 3:
bucketName = splits[1]
objectName = splits[2]
}
return bucketName, objectName
}
// path2Object gives objectName from URL path
func path2Object(path string) (objectName string) {
pathSplits := strings.SplitN(path, "?", 2)
@@ -277,6 +294,7 @@ func (r *request) getCanonicalRequest(hashedPayload string) string {
encodedPath, _ := urlEncodeName(r.req.URL.Path)
// convert any space strings back to "+"
encodedPath = strings.Replace(encodedPath, "+", "%20", -1)
encodedPath = strings.Replace(encodedPath, "%2B", "+", -1)
canonicalRequest := strings.Join([]string{
r.req.Method,
encodedPath,
+3
View File
@@ -71,6 +71,9 @@ type Error struct {
// trace the return path with Probe.Trace and finally handle reporting or quitting
// at the top level.
func New(e error) *Error {
if e == nil {
return nil
}
Err := Error{sync.RWMutex{}, e, GetSysInfo(), []tracePoint{}}
return Err.trace()
}
+1 -1
View File
@@ -335,7 +335,7 @@ func (c *C) logPanic(skip int, value interface{}) {
if name == "Value.call" && strings.HasSuffix(path, valueGo) {
continue
}
if (name == "call16" || name == "call32") && strings.Contains(path, asmGo) {
if name == "call16" && strings.Contains(path, asmGo) {
continue
}
c.logf("%s:%d\n in %s", nicePath(file), line, name)
+3 -3
View File
@@ -64,14 +64,14 @@ func runAccessCmd(ctx *cli.Context) {
config := mustGetMcConfig()
acl := bucketACL(ctx.Args().First())
if !acl.isValidBucketACL() {
ifFatal(probe.New(errInvalidACL{acl: acl.String()}))
Fatal(probe.New(errInvalidACL{acl: acl.String()}))
}
for _, arg := range ctx.Args().Tail() {
targetURL, err := getExpandedURL(arg, config.Aliases)
ifFatal(err)
Fatal(err)
err = doUpdateAccessCmd(targetURL, acl)
ifFatal(err)
Fatal(err)
}
}
+2 -2
View File
@@ -67,8 +67,8 @@ func runCatCmd(ctx *cli.Context) {
// Convert arguments to URLs: expand alias, fix format...
for _, arg := range ctx.Args() {
sourceURL, err := getExpandedURL(arg, config.Aliases)
ifFatal(err)
ifFatal(doCatCmd(sourceURL))
Fatal(err)
Fatal(doCatCmd(sourceURL))
}
}
+1 -1
View File
@@ -67,7 +67,7 @@ func runConfigCmd(ctx *cli.Context) {
console.Fatalf("Incorrect number of arguments, please read \"mc config help\". %s", errInvalidArgument{})
}
msg, err := doConfig(arg, tailArgs)
ifFatal(err)
Fatal(err)
console.Infoln(msg)
}
+8 -8
View File
@@ -66,7 +66,7 @@ func getMcConfigDir() (string, *probe.Error) {
// mustGetMcConfigDir - construct minio client config folder or fail
func mustGetMcConfigDir() (configDir string) {
configDir, err := getMcConfigDir()
ifFatal(err)
Fatal(err)
return configDir
}
@@ -94,7 +94,7 @@ func getMcConfigPath() (string, *probe.Error) {
// mustGetMcConfigPath - similar to getMcConfigPath, ignores errors
func mustGetMcConfigPath() string {
path, err := getMcConfigPath()
ifFatal(err)
Fatal(err)
return path
}
@@ -132,7 +132,7 @@ func getMcConfig() (*configV1, *probe.Error) {
// mustGetMcConfig - reads configuration file and returns configs, exits on error
func mustGetMcConfig() *configV1 {
config, err := getMcConfig()
ifFatal(err)
Fatal(err)
return config
}
@@ -175,9 +175,9 @@ func migrateConfigV1ToV101() {
}
conf := newConfigV1()
config, err := quick.New(conf)
ifFatal(err)
Fatal(err)
err = config.Load(mustGetMcConfigPath())
ifFatal(err)
Fatal(err)
conf = config.Data().(*configV1)
// version is the same return
@@ -206,9 +206,9 @@ func migrateConfigV1ToV101() {
{
newConfig, err := quick.New(conf)
ifFatal(err)
Fatal(err)
err = newConfig.Save(mustGetMcConfigPath())
ifFatal(err)
Fatal(err)
}
console.Infof("Successfully migrated %s from version: %s to version: %s\n", mustGetMcConfigPath(), mcPreviousConfigVersion, mcCurrentConfigVersion)
@@ -286,6 +286,6 @@ func newConfig() (config quick.Config, err *probe.Error) {
// mustNewConfig instantiates a new config handler, exists upon error
func mustNewConfig() quick.Config {
config, err := newConfig()
ifFatal(err)
Fatal(err)
return config
}
+2 -2
View File
@@ -154,7 +154,7 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
break
}
if cpURLs.Error != nil {
ifError(cpURLs.Error)
Error(cpURLs.Error)
break
}
@@ -221,7 +221,7 @@ func doCopyCmdSession(session *sessionV2) {
session.Header.LastCopied = cpURLs.SourceContent.Name
} else {
console.Println()
ifError(cpURLs.Error)
Error(cpURLs.Error)
}
case <-trapCh: // Receive interrupt notification.
session.Close()
+13 -13
View File
@@ -108,12 +108,12 @@ func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) {
}
srcURL := srcURLs[0]
_, srcContent, err := url2Stat(srcURL)
ifFatal(err)
Fatal(err)
if srcContent.Type.IsDir() {
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
}
if !srcContent.Type.IsRegular() {
ifFatal(probe.New(errSourceIsNotFile{URL: srcURL}))
Fatal(probe.New(errSourceIsNotFile{URL: srcURL}))
}
}
@@ -124,19 +124,19 @@ func checkCopySyntaxTypeB(srcURLs []string, tgtURL string) {
}
srcURL := srcURLs[0]
_, srcContent, err := url2Stat(srcURL)
ifFatal(err)
Fatal(err)
if srcContent.Type.IsDir() {
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
}
if !srcContent.Type.IsRegular() {
ifFatal(probe.New(errSourceIsNotFile{URL: srcURL}))
Fatal(probe.New(errSourceIsNotFile{URL: srcURL}))
}
_, tgtContent, err := url2Stat(tgtURL)
// Target exist?.
if err == nil {
if !tgtContent.Type.IsDir() {
ifFatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
Fatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
}
}
}
@@ -149,16 +149,16 @@ func checkCopySyntaxTypeC(srcURLs []string, tgtURL string) {
srcURL := srcURLs[0]
srcURL = stripRecursiveURL(srcURL)
_, srcContent, err := url2Stat(srcURL)
ifFatal(err)
Fatal(err)
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
ifFatal(probe.New(errSourceIsNotDir{URL: srcURL}))
Fatal(probe.New(errSourceIsNotDir{URL: srcURL}))
}
_, tgtContent, err := url2Stat(tgtURL)
// Target exist?.
if err == nil {
if !tgtContent.Type.IsDir() {
ifFatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
Fatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
}
}
}
@@ -169,18 +169,18 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
if isURLRecursive(srcURL) {
srcURL = stripRecursiveURL(srcURL)
_, srcContent, err := url2Stat(srcURL)
ifFatal(err)
Fatal(err)
if !srcContent.Type.IsDir() { // Ellipses is supported only for folders.
ifFatal(probe.New(errSourceIsNotDir{URL: srcURL}))
Fatal(probe.New(errSourceIsNotDir{URL: srcURL}))
}
} else { // Regular URL.
_, srcContent, err := url2Stat(srcURL)
ifFatal(err)
Fatal(err)
if srcContent.Type.IsDir() {
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
}
if !srcContent.Type.IsRegular() {
ifFatal(probe.New(errSourceIsNotFile{URL: srcURL}))
Fatal(probe.New(errSourceIsNotFile{URL: srcURL}))
}
}
}
@@ -188,7 +188,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
// Target exist?.
if err == nil {
if !tgtContent.Type.IsDir() {
ifFatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
Fatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
}
}
}
+2 -2
View File
@@ -63,9 +63,9 @@ func runDiffCmd(ctx *cli.Context) {
var err *probe.Error
firstURL, err = getExpandedURL(firstURL, config.Aliases)
ifFatal(err)
Fatal(err)
secondURL, err = getExpandedURL(secondURL, config.Aliases)
ifFatal(err)
Fatal(err)
if isURLRecursive(secondURL) {
console.Fatalf("Second URL cannot be recursive. %s\n", errInvalidArgument{})
}
+43 -13
View File
@@ -1,3 +1,19 @@
/*
* Minio Client (C) 2014, 2015 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 (
@@ -5,27 +21,41 @@ import (
"github.com/minio/minio/pkg/probe"
)
func ifFatal(err *probe.Error) {
switch err {
case nil:
// nothing to print
default:
if !globalDebugFlag {
console.Fatalln(err.ToError())
// Fatal wrapper function which takes error and selectively prints stack frames if available on debug
func Fatal(err error) {
if err == nil {
return
}
switch e := err.(type) {
case *probe.Error:
if e == nil {
return
}
if !globalDebugFlag {
console.Fatalln(e.ToError())
}
console.Fatalln(err)
default:
console.Fatalln(err)
}
}
func ifError(err *probe.Error) {
switch err {
case nil:
// nothing to print
default:
// Error synonymous with Fatal but doesn't exit on error != nil
func Error(err error) {
if err == nil {
return
}
switch e := err.(type) {
case *probe.Error:
if e == nil {
return
}
if !globalDebugFlag {
console.Errorln(err.ToError())
console.Errorln(e.ToError())
return
}
console.Errorln(err)
default:
console.Errorln(err)
}
}
+3 -3
View File
@@ -111,14 +111,14 @@ func firstTimeRun() {
console.Fatalf("Unable to create ‘mc’ config folder. %s\n", err)
}
config, err := newConfig()
ifFatal(err)
Fatal(err)
err = writeConfig(config)
ifFatal(err)
Fatal(err)
console.Infoln("Configuration written to [" + mustGetMcConfigPath() + "]. Please update your access credentials.")
}
if !isSessionDirExists() {
err := createSessionDir()
ifFatal(err)
Fatal(err)
}
checkGolangVersion()
}
+2 -2
View File
@@ -83,10 +83,10 @@ func runListCmd(ctx *cli.Context) {
config := mustGetMcConfig()
for _, arg := range args {
targetURL, err := getExpandedURL(arg, config.Aliases)
ifFatal(err)
Fatal(err)
// if recursive strip off the "..."
newTargetURL := stripRecursiveURL(targetURL)
ifFatal(doListCmd(newTargetURL, isURLRecursive(targetURL)))
Fatal(doListCmd(newTargetURL, isURLRecursive(targetURL)))
}
}
+2 -2
View File
@@ -79,11 +79,11 @@ func doList(clnt client.Client, recursive bool) *probe.Error {
switch contentCh.Err.ToError().(type) {
// handle this specifically for filesystem
case client.ISBrokenSymlink:
ifError(contentCh.Err)
Error(contentCh.Err)
continue
}
if os.IsNotExist(contentCh.Err.ToError()) || os.IsPermission(contentCh.Err.ToError()) {
ifError(contentCh.Err)
Error(contentCh.Err)
continue
}
err = contentCh.Err
+1 -1
View File
@@ -38,7 +38,7 @@ func checkConfig() {
// Ensures config file is sane
{
_, err := getMcConfig()
ifFatal(err)
Fatal(err)
}
}
+4 -2
View File
@@ -60,8 +60,10 @@ func runMakeBucketCmd(ctx *cli.Context) {
config := mustGetMcConfig()
for _, arg := range ctx.Args() {
targetURL, err := getExpandedURL(arg, config.Aliases)
ifFatal(err)
ifFatal(doMakeBucketCmd(targetURL))
Fatal(err)
err = doMakeBucketCmd(targetURL)
Fatal(err)
console.Infoln("Bucket created successfully : " + targetURL)
}
}
+2 -2
View File
@@ -152,7 +152,7 @@ func doPrepareMirrorURLs(session *sessionV2, trapCh <-chan bool) {
break
}
if sURLs.Error != nil {
ifError(sURLs.Error)
Error(sURLs.Error)
break
}
if sURLs.isEmpty() {
@@ -221,7 +221,7 @@ func doMirrorCmdSession(session *sessionV2) {
session.Header.LastCopied = sURLs.SourceContent.Name
} else {
console.Println()
ifError(sURLs.Error)
Error(sURLs.Error)
}
case <-trapCh: // Receive interrupt notification.
session.Close()
+6 -6
View File
@@ -57,7 +57,7 @@ func checkMirrorSyntax(ctx *cli.Context) {
// extract URLs.
URLs, err := args2URLs(ctx.Args())
ifFatal(err)
Fatal(err)
srcURL := URLs[0]
tgtURLs := URLs[1:]
@@ -66,7 +66,7 @@ func checkMirrorSyntax(ctx *cli.Context) {
// Source cannot be a folder (except when recursive)
if !isURLRecursive(srcURL) {
_, srcContent, err := url2Stat(srcURL)
ifFatal(err)
Fatal(err)
if !srcContent.Type.IsRegular() {
if srcContent.Type.IsDir() {
@@ -93,16 +93,16 @@ func checkMirrorSyntax(ctx *cli.Context) {
}
srcURL = stripRecursiveURL(srcURL)
_, srcContent, err := url2Stat(srcURL)
ifFatal(err)
Fatal(err)
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
ifFatal(probe.New(errSourceIsNotDir{URL: srcURL}))
Fatal(probe.New(errSourceIsNotDir{URL: srcURL}))
}
for _, tgtURL := range tgtURLs {
_, content, err := url2Stat(tgtURL)
if err == nil {
if !content.Type.IsDir() {
ifFatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
Fatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
}
}
}
@@ -165,7 +165,7 @@ func deltaSourceTargets(sourceClnt client.Client, targetClnts []client.Client) <
if !targetTrie.Match(patricia.Prefix(matchName)) {
sourceURLDelimited := sourceClnt.URL().String()[:strings.LastIndex(sourceClnt.URL().String(),
string(sourceClnt.URL().Separator))+1]
newTargetURLParse := targetClnts[i].URL()
newTargetURLParse := *targetClnts[i].URL()
newTargetURLParse.Path = filepath.Join(newTargetURLParse.Path, matchName)
sourceContent.Size = sourceTrie.Get(patricia.Prefix(matchName)).(int64)
sourceContent.Name = sourceURLDelimited + matchName
+5 -2
View File
@@ -118,8 +118,11 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error {
bucket, object := c.url2BucketAndObject()
err := c.api.PutObject(bucket, object, "application/octet-stream", size, data)
if err != nil {
if minio.ToErrorResponse(err).Code == "MethodNotAllowed" {
return probe.New(ObjectAlreadyExists{Object: object})
errResponse := minio.ToErrorResponse(err)
if errResponse != nil {
if errResponse.Code == "MethodNotAllowed" {
return probe.New(ObjectAlreadyExists{Object: object})
}
}
return probe.New(err)
}
+5 -5
View File
@@ -85,7 +85,7 @@ func clearSession(sid string) {
if sid == "all" {
for _, sid := range getSessionIDs() {
session, err := loadSessionV2(sid)
ifFatal(err)
Fatal(err)
session.Delete()
}
return
@@ -96,7 +96,7 @@ func clearSession(sid string) {
}
session, err := loadSessionV2(sid)
ifFatal(err)
Fatal(err)
if session != nil {
session.Delete()
}
@@ -119,13 +119,13 @@ func runSessionCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "session", 1) // last argument is exit code
}
if !isSessionDirExists() {
ifFatal(createSessionDir())
Fatal(createSessionDir())
}
switch strings.TrimSpace(ctx.Args().First()) {
// list resumable sessions
case "list":
err := listSessions()
ifFatal(err)
Fatal(err)
case "resume":
if len(ctx.Args().Tail()) != 1 {
cli.ShowCommandHelpAndExit(ctx, "session", 1) // last argument is exit code
@@ -140,7 +140,7 @@ func runSessionCmd(ctx *cli.Context) {
console.Fatalln(errInvalidSessionID{id: sid})
}
s, err := loadSessionV2(sid)
ifFatal(err)
Fatal(err)
// extra check for testing purposes
if s == nil {
return
View File
+1 -1
View File
@@ -104,7 +104,7 @@ func runUpdateCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
}
msg, err := doUpdateCheck()
ifFatal(err)
Fatal(err)
// no msg do not print one
if msg != "" {
console.Infoln(msg)