Add error messages to fatalIf and errorIf
This commit is contained in:
+4
-4
@@ -64,13 +64,13 @@ func mainAccess(ctx *cli.Context) {
|
||||
config := mustGetMcConfig()
|
||||
acl := bucketACL(ctx.Args().First())
|
||||
if !acl.isValidBucketACL() {
|
||||
fatalIf(probe.NewError(errInvalidACL{acl: acl.String()}))
|
||||
fatalIf(probe.NewError(errInvalidACL{acl: acl.String()}), "ACL validation failed.")
|
||||
}
|
||||
for _, arg := range ctx.Args().Tail() {
|
||||
targetURL, err := getExpandedURL(arg, config.Aliases)
|
||||
fatalIf(err)
|
||||
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
|
||||
fatalIf(err, "Unable to validate given URL.")
|
||||
|
||||
fatalIf(doUpdateAccessCmd(targetURL, acl))
|
||||
fatalIf(doUpdateAccessCmd(targetURL, acl), "Unable to set access permissions.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -70,11 +70,11 @@ func mainCat(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
if stdinMode {
|
||||
fatalIf(catOut(os.Stdin))
|
||||
fatalIf(catOut(os.Stdin), "Unable to read from stdin")
|
||||
} else {
|
||||
// Convert arguments to URLs: expand alias, fix format...
|
||||
for _, arg := range ctx.Args() {
|
||||
fatalIf(catURL(arg))
|
||||
fatalIf(catURL(arg), "Unable to read from URL")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func mainCat(ctx *cli.Context) {
|
||||
func catURL(sourceURL string) *probe.Error {
|
||||
config := mustGetMcConfig()
|
||||
|
||||
URL, err := getExpandedURL(sourceURL, config.Aliases)
|
||||
URL, err := getCanonicalizedURL(sourceURL, config.Aliases)
|
||||
if err != nil {
|
||||
return err.Trace(sourceURL)
|
||||
}
|
||||
|
||||
@@ -60,9 +60,13 @@ func (s *CmdTestSuite) TestCatContext(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "cat", server.URL + "/invalid"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
}
|
||||
|
||||
-15
@@ -74,21 +74,6 @@ func (s *CmdTestSuite) SetUpSuite(c *C) {
|
||||
perr = createSessionDir()
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
perr = doConfig("invalid", nil)
|
||||
c.Assert(perr, Not(IsNil))
|
||||
|
||||
perr = doConfig("alias", []string{"test", "https://test.io"})
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
perr = doConfig("alias", []string{"test", "https://test.io"})
|
||||
c.Assert(perr, Not(IsNil))
|
||||
|
||||
perr = doConfig("alias", []string{"test", "htt://test.io"})
|
||||
c.Assert(perr, Not(IsNil))
|
||||
|
||||
perr = doConfig("alias", []string{"readonly", "https://new.test.io"})
|
||||
c.Assert(perr, Not(IsNil))
|
||||
|
||||
app = registerApp()
|
||||
}
|
||||
|
||||
|
||||
+11
-21
@@ -52,7 +52,7 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// mainConfig is the handle for "mc config" sub-command
|
||||
// mainConfig is the handle for "mc config" sub-command. writes configuration data in json format to config file.
|
||||
func mainConfig(ctx *cli.Context) {
|
||||
// show help if nothing is set
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
@@ -67,30 +67,20 @@ func mainConfig(ctx *cli.Context) {
|
||||
console.Fatalf("Incorrect number of arguments, please read \"mc config help\". %s", errInvalidArgument{})
|
||||
}
|
||||
configPath, err := getMcConfigPath()
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to get mc config path")
|
||||
|
||||
fatalIf(doConfig(arg, tailArgs))
|
||||
// upon success
|
||||
console.Infoln("Alias written successfully to [" + configPath + "].")
|
||||
}
|
||||
|
||||
// saveConfig writes configuration data in json format to config file.
|
||||
func saveConfig(arg string, aliases []string) *probe.Error {
|
||||
switch arg {
|
||||
case "alias":
|
||||
config, err := addAlias(aliases)
|
||||
if err != nil {
|
||||
return err.Trace()
|
||||
}
|
||||
return writeConfig(config).Trace()
|
||||
default:
|
||||
return probe.NewError(errInvalidArgument{})
|
||||
}
|
||||
}
|
||||
config, err := addAlias(tailArgs)
|
||||
fatalIf(err, "Unable to set alias name")
|
||||
|
||||
// doConfig is the handler for "mc config" sub-command.
|
||||
func doConfig(arg string, aliases []string) *probe.Error {
|
||||
return saveConfig(arg, aliases).Trace()
|
||||
err = writeConfig(config)
|
||||
fatalIf(err, "Unable to write alias name")
|
||||
default:
|
||||
fatalIf(probe.NewError(errInvalidArgument{}), "Unable to configure")
|
||||
}
|
||||
// upon success
|
||||
console.Infoln("Alias written successfully to [" + configPath + "].")
|
||||
}
|
||||
|
||||
// addAlias - add new aliases
|
||||
|
||||
@@ -66,7 +66,8 @@ func getMcConfigDir() (string, *probe.Error) {
|
||||
// mustGetMcConfigDir - construct minio client config folder or fail
|
||||
func mustGetMcConfigDir() (configDir string) {
|
||||
configDir, err := getMcConfigDir()
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to get mcConfigDir")
|
||||
|
||||
return configDir
|
||||
}
|
||||
|
||||
@@ -94,7 +95,8 @@ func getMcConfigPath() (string, *probe.Error) {
|
||||
// mustGetMcConfigPath - similar to getMcConfigPath, ignores errors
|
||||
func mustGetMcConfigPath() string {
|
||||
path, err := getMcConfigPath()
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to get mcConfigPath")
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
@@ -132,7 +134,8 @@ func getMcConfig() (*configV1, *probe.Error) {
|
||||
// mustGetMcConfig - reads configuration file and returns configs, exits on error
|
||||
func mustGetMcConfig() *configV1 {
|
||||
config, err := getMcConfig()
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to get mcConfig")
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
@@ -150,6 +153,9 @@ func isMcConfigExists() bool {
|
||||
|
||||
// writeConfig - write configuration file
|
||||
func writeConfig(config quick.Config) *probe.Error {
|
||||
if config == nil {
|
||||
return probe.NewError(errInvalidArgument{})
|
||||
}
|
||||
err := createMcConfigDir()
|
||||
if err != nil {
|
||||
return err.Trace()
|
||||
@@ -175,9 +181,10 @@ func migrateConfigV1ToV101() {
|
||||
}
|
||||
conf := newConfigV1()
|
||||
config, err := quick.New(conf)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to initialize quick config")
|
||||
|
||||
err = config.Load(mustGetMcConfigPath())
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to load config")
|
||||
|
||||
conf = config.Data().(*configV1)
|
||||
// version is the same return
|
||||
@@ -205,9 +212,10 @@ func migrateConfigV1ToV101() {
|
||||
}
|
||||
|
||||
newConfig, perr := quick.New(conf)
|
||||
fatalIf(perr)
|
||||
fatalIf(perr, "Unable to initialize quick config")
|
||||
|
||||
perr = newConfig.Save(mustGetMcConfigPath())
|
||||
fatalIf(perr)
|
||||
fatalIf(perr, "Unable to save config")
|
||||
|
||||
console.Infof("Successfully migrated %s from version: %s to version: %s\n", mustGetMcConfigPath(), globalMCPreviousConfigVersion, globalMCCurrentConfigVersion)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 (
|
||||
"os"
|
||||
|
||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
func (s *CmdTestSuite) TestConfigContext(c *C) {
|
||||
err := app.Run([]string{os.Args[0], "config", "invalid"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "config", "alias", "test", "htt://test.io"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "config", "alias", "test", "http://test.io"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
}
|
||||
+2
-4
@@ -159,8 +159,7 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
|
||||
break
|
||||
}
|
||||
if cpURLs.Error != nil {
|
||||
console.PrintC("Failed to prepare copy URLs, ")
|
||||
errorIf(cpURLs.Error)
|
||||
errorIf(cpURLs.Error, "Failed to prepare copy URLs.")
|
||||
break
|
||||
}
|
||||
|
||||
@@ -231,8 +230,7 @@ func doCopyCmdSession(session *sessionV2) {
|
||||
session.Header.LastCopied = cpURLs.SourceContent.Name
|
||||
} else {
|
||||
console.Println()
|
||||
console.PrintC(fmt.Sprintf("Failed to copy ‘%s’, ", cpURLs.SourceContent.Name))
|
||||
errorIf(cpURLs.Error)
|
||||
errorIf(cpURLs.Error, fmt.Sprintf("Failed to copy ‘%s’. ", cpURLs.SourceContent.Name))
|
||||
}
|
||||
case <-trapCh: // Receive interrupt notification.
|
||||
session.Close()
|
||||
|
||||
@@ -108,12 +108,13 @@ func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) {
|
||||
}
|
||||
srcURL := srcURLs[0]
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
|
||||
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() {
|
||||
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}))
|
||||
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}), "Invalid source type")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,19 +125,20 @@ func checkCopySyntaxTypeB(srcURLs []string, tgtURL string) {
|
||||
}
|
||||
srcURL := srcURLs[0]
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
|
||||
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() {
|
||||
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}))
|
||||
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}), "Invalid source type")
|
||||
}
|
||||
|
||||
_, tgtContent, err := url2Stat(tgtURL)
|
||||
// Target exist?.
|
||||
if err == nil {
|
||||
if !tgtContent.Type.IsDir() {
|
||||
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
|
||||
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}), "Invalid target type")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,16 +151,16 @@ func checkCopySyntaxTypeC(srcURLs []string, tgtURL string) {
|
||||
srcURL := srcURLs[0]
|
||||
srcURL = stripRecursiveURL(srcURL)
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
|
||||
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
|
||||
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}))
|
||||
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}), "Invalid source type")
|
||||
}
|
||||
_, tgtContent, err := url2Stat(tgtURL)
|
||||
// Target exist?.
|
||||
if err == nil {
|
||||
if !tgtContent.Type.IsDir() {
|
||||
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
|
||||
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}), "Invalid target type")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,18 +171,20 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
|
||||
if isURLRecursive(srcURL) {
|
||||
srcURL = stripRecursiveURL(srcURL)
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
|
||||
if !srcContent.Type.IsDir() { // Ellipses is supported only for folders.
|
||||
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}))
|
||||
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}), "Invalid source type")
|
||||
}
|
||||
} else { // Regular URL.
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
|
||||
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() {
|
||||
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}))
|
||||
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}), "Unable to read from source url")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,7 +192,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
|
||||
// Target exist?.
|
||||
if err == nil {
|
||||
if !tgtContent.Type.IsDir() {
|
||||
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
|
||||
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}), "Unable to write to target url")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ func (s *CmdTestSuite) TestCopyContext(c *C) {
|
||||
err := app.Run([]string{os.Args[0], "cp", server.URL + "/invalid...", server.URL + "/bucket"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsError, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsError = false
|
||||
}
|
||||
|
||||
+7
-6
@@ -62,17 +62,18 @@ func mainDiff(ctx *cli.Context) {
|
||||
secondURL := ctx.Args()[1]
|
||||
|
||||
var err *probe.Error
|
||||
firstURL, err = getExpandedURL(firstURL, config.Aliases)
|
||||
fatalIf(err)
|
||||
secondURL, err = getExpandedURL(secondURL, config.Aliases)
|
||||
fatalIf(err)
|
||||
firstURL, err = getCanonicalizedURL(firstURL, config.Aliases)
|
||||
fatalIf(err, "Unable to canonicalize first URL.")
|
||||
|
||||
secondURL, err = getCanonicalizedURL(secondURL, config.Aliases)
|
||||
fatalIf(err, "Unable to canonicalize second URL.")
|
||||
|
||||
if isURLRecursive(secondURL) {
|
||||
console.Fatalf("Second URL cannot be recursive. %s\n", errInvalidArgument{})
|
||||
}
|
||||
newFirstURL := stripRecursiveURL(firstURL)
|
||||
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
|
||||
fatalIf(diff.err)
|
||||
console.PrintC(diff.message)
|
||||
fatalIf(diff.err, diff.message)
|
||||
}
|
||||
console.Println()
|
||||
}
|
||||
|
||||
@@ -94,13 +94,20 @@ func (s *CmdTestSuite) TestDiffContext(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "diff", server.URL + "/bucket...", server.URL + "/bucket"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "diff", server.URL + "/invalid", server.URL + "/invalid..."})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
||||
@@ -25,17 +26,19 @@ import (
|
||||
)
|
||||
|
||||
// fatalIf wrapper function which takes error and selectively prints stack frames if available on debug
|
||||
func fatalIf(err *probe.Error) {
|
||||
func fatalIf(err *probe.Error, msg string) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if globalJSONFlag {
|
||||
errorMessage := struct {
|
||||
Message string `json:"message"`
|
||||
Cause error `json:"cause"`
|
||||
Type string `json:"type"`
|
||||
CallTrace []probe.TracePoint `json:"trace,omitempty"`
|
||||
SysInfo map[string]string `json:"sysinfo"`
|
||||
}{
|
||||
Message: msg,
|
||||
Type: "Fatal",
|
||||
Cause: err.ToGoError(),
|
||||
SysInfo: err.SysInfo,
|
||||
@@ -51,23 +54,25 @@ func fatalIf(err *probe.Error) {
|
||||
os.Exit(1)
|
||||
}
|
||||
if !globalDebugFlag {
|
||||
console.Fatalln(err.ToGoError())
|
||||
console.Fatalln(fmt.Sprintf("%s %s", msg, err.ToGoError()))
|
||||
}
|
||||
console.Fatalln(err)
|
||||
console.Fatalln(fmt.Sprintf("%s %s", msg, err))
|
||||
}
|
||||
|
||||
// errorIf synonymous with fatalIf but doesn't exit on error != nil
|
||||
func errorIf(err *probe.Error) {
|
||||
func errorIf(err *probe.Error, msg string) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if globalJSONFlag {
|
||||
errorMessage := struct {
|
||||
Message string `json:"message"`
|
||||
Cause error `json:"cause"`
|
||||
Type string `json:"type"`
|
||||
CallTrace []probe.TracePoint `json:"trace,omitempty"`
|
||||
SysInfo map[string]string `json:"sysinfo"`
|
||||
}{
|
||||
Message: msg,
|
||||
Type: "Error",
|
||||
Cause: err.ToGoError(),
|
||||
SysInfo: err.SysInfo,
|
||||
@@ -83,8 +88,8 @@ func errorIf(err *probe.Error) {
|
||||
return
|
||||
}
|
||||
if !globalDebugFlag {
|
||||
console.Errorln(err.ToGoError())
|
||||
console.Errorln(fmt.Sprintf("%s %s", msg, err.ToGoError()))
|
||||
return
|
||||
}
|
||||
console.Errorln(err)
|
||||
console.Errorln(fmt.Sprintf("%s %s", msg, err))
|
||||
}
|
||||
|
||||
+4
-3
@@ -82,11 +82,12 @@ func mainList(ctx *cli.Context) {
|
||||
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range args {
|
||||
targetURL, err := getExpandedURL(arg, config.Aliases)
|
||||
fatalIf(err)
|
||||
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
|
||||
fatalIf(err, "Unable to canonicalize URL")
|
||||
|
||||
// if recursive strip off the "..."
|
||||
newTargetURL := stripRecursiveURL(targetURL)
|
||||
fatalIf(doListCmd(newTargetURL, isURLRecursive(targetURL)))
|
||||
fatalIf(doListCmd(newTargetURL, isURLRecursive(targetURL)), "Unable to list target URL")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,11 +79,11 @@ func doList(clnt client.Client, recursive bool) *probe.Error {
|
||||
switch contentCh.Err.ToGoError().(type) {
|
||||
// handle this specifically for filesystem
|
||||
case client.ISBrokenSymlink:
|
||||
errorIf(contentCh.Err.Trace())
|
||||
errorIf(contentCh.Err.Trace(), "Unable to list broken link.")
|
||||
continue
|
||||
}
|
||||
if os.IsNotExist(contentCh.Err.ToGoError()) || os.IsPermission(contentCh.Err.ToGoError()) {
|
||||
errorIf(contentCh.Err.Trace())
|
||||
errorIf(contentCh.Err.Trace(), "Unable to list.")
|
||||
continue
|
||||
}
|
||||
err = contentCh.Err.Trace()
|
||||
|
||||
@@ -69,9 +69,13 @@ func (s *CmdTestSuite) TestLSContext(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsError, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "ls", server.URL + "/invalid"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
}
|
||||
|
||||
@@ -38,10 +38,8 @@ func checkConfig() {
|
||||
}
|
||||
|
||||
// Ensures config file is sane
|
||||
{
|
||||
_, err := getMcConfig()
|
||||
fatalIf(err)
|
||||
}
|
||||
_, perr := getMcConfig()
|
||||
fatalIf(perr, "Unable to read config")
|
||||
}
|
||||
|
||||
func migrate() {
|
||||
@@ -90,8 +88,7 @@ func registerBefore(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
if err := console.SetTheme(themeName); err != nil {
|
||||
console.Errorf("Failed to set theme ‘%s’.", themeName)
|
||||
errorIf(err)
|
||||
errorIf(err, "Unable to set theme")
|
||||
}
|
||||
|
||||
verifyMCRuntime()
|
||||
|
||||
+4
-4
@@ -59,11 +59,11 @@ func mainMakeBucket(ctx *cli.Context) {
|
||||
}
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range ctx.Args() {
|
||||
targetURL, err := getExpandedURL(arg, config.Aliases)
|
||||
fatalIf(err)
|
||||
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
|
||||
fatalIf(err, "Unable to canonicalize URL")
|
||||
|
||||
fatalIf(doMakeBucketCmd(targetURL), "Unable to make bucket")
|
||||
|
||||
err = doMakeBucketCmd(targetURL)
|
||||
fatalIf(err)
|
||||
console.Infoln("Bucket created successfully : " + targetURL)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,9 +57,13 @@ func (s *CmdTestSuite) TestMBContext(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "mb", server.URL + "/$.bucket"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
}
|
||||
@@ -69,18 +73,30 @@ func (s *CmdTestSuite) TestAccessContext(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "access", "public", server.URL + "/bucket"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "access", "readonly", server.URL + "/bucket"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "access", "authenticated", server.URL + "/bucket"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "access", "invalid", server.URL + "/bucket"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
+2
-4
@@ -156,8 +156,7 @@ func doPrepareMirrorURLs(session *sessionV2, trapCh <-chan bool) {
|
||||
break
|
||||
}
|
||||
if sURLs.Error != nil {
|
||||
console.PrintC("Failed to prepare mirror URLs, ")
|
||||
errorIf(sURLs.Error)
|
||||
errorIf(sURLs.Error, "Unable to prepare mirror URLs.")
|
||||
break
|
||||
}
|
||||
if sURLs.isEmpty() {
|
||||
@@ -230,8 +229,7 @@ func doMirrorCmdSession(session *sessionV2) {
|
||||
session.Header.LastCopied = sURLs.SourceContent.Name
|
||||
} else {
|
||||
console.Println()
|
||||
console.PrintC(fmt.Sprintf("Failed to mirror ‘%s’, ", sURLs.SourceContent.Name))
|
||||
errorIf(sURLs.Error)
|
||||
errorIf(sURLs.Error, fmt.Sprintf("Failed to mirror ‘%s’.", sURLs.SourceContent.Name))
|
||||
}
|
||||
case <-trapCh: // Receive interrupt notification.
|
||||
session.Close()
|
||||
|
||||
+7
-7
@@ -57,7 +57,7 @@ func checkMirrorSyntax(ctx *cli.Context) {
|
||||
|
||||
// extract URLs.
|
||||
URLs, err := args2URLs(ctx.Args())
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to convert args to URLs")
|
||||
|
||||
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)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to stat URL")
|
||||
|
||||
if !srcContent.Type.IsRegular() {
|
||||
if srcContent.Type.IsDir() {
|
||||
@@ -91,18 +91,18 @@ func checkMirrorSyntax(ctx *cli.Context) {
|
||||
if len(tgtURLs) == 0 && tgtURLs == nil {
|
||||
console.Fatalf("Invalid number of target arguments to mirror command. %s\n", errInvalidArgument{})
|
||||
}
|
||||
srcURL = stripRecursiveURL(srcURL)
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err)
|
||||
|
||||
_, srcContent, err := url2Stat(stripRecursiveURL(srcURL))
|
||||
fatalIf(err, "Unable to stat source URL.")
|
||||
|
||||
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
|
||||
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}))
|
||||
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}), "Invalid source type.")
|
||||
}
|
||||
for _, tgtURL := range tgtURLs {
|
||||
_, content, err := url2Stat(tgtURL)
|
||||
if err == nil {
|
||||
if !content.Type.IsDir() {
|
||||
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
|
||||
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}), "Invalid target type.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-6
@@ -85,7 +85,8 @@ func clearSession(sid string) {
|
||||
if sid == "all" {
|
||||
for _, sid := range getSessionIDs() {
|
||||
session, err := loadSessionV2(sid)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to load session")
|
||||
|
||||
session.Delete()
|
||||
}
|
||||
return
|
||||
@@ -96,7 +97,8 @@ func clearSession(sid string) {
|
||||
}
|
||||
|
||||
session, err := loadSessionV2(sid)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to load session")
|
||||
|
||||
if session != nil {
|
||||
session.Delete()
|
||||
}
|
||||
@@ -119,13 +121,12 @@ func mainSession(ctx *cli.Context) {
|
||||
cli.ShowCommandHelpAndExit(ctx, "session", 1) // last argument is exit code
|
||||
}
|
||||
if !isSessionDirExists() {
|
||||
fatalIf(createSessionDir())
|
||||
fatalIf(createSessionDir(), "Unable to create session")
|
||||
}
|
||||
switch strings.TrimSpace(ctx.Args().First()) {
|
||||
// list resumable sessions
|
||||
case "list":
|
||||
err := listSessions()
|
||||
fatalIf(err)
|
||||
fatalIf(listSessions(), "Unable to list sessions")
|
||||
case "resume":
|
||||
if len(ctx.Args().Tail()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "session", 1) // last argument is exit code
|
||||
@@ -140,7 +141,8 @@ func mainSession(ctx *cli.Context) {
|
||||
console.Fatalln(errInvalidSessionID{id: sid})
|
||||
}
|
||||
s, err := loadSessionV2(sid)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to load session")
|
||||
|
||||
// extra check for testing purposes
|
||||
if s == nil {
|
||||
return
|
||||
|
||||
@@ -59,23 +59,37 @@ func (s *CmdTestSuite) TestSessionContext(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "session", "clear", "all"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "session", "resume", "invalid"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "session", "clear", "invalid"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
perr := createSessionDir()
|
||||
c.Assert(perr, IsNil)
|
||||
c.Assert(isSessionDirExists(), Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
session := newSessionV2()
|
||||
c.Assert(session.Header.CommandArgs, IsNil)
|
||||
c.Assert(len(session.SessionID), Equals, 8)
|
||||
@@ -86,4 +100,7 @@ func (s *CmdTestSuite) TestSessionContext(c *C) {
|
||||
err = app.Run([]string{os.Args[0], "session", "clear", session.SessionID})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
}
|
||||
|
||||
+4
-5
@@ -73,13 +73,12 @@ func mainShare(ctx *cli.Context) {
|
||||
if len(args) == 2 {
|
||||
var err error
|
||||
expires, err = time.ParseDuration(args.Last())
|
||||
fatalIf(probe.NewError(err))
|
||||
fatalIf(probe.NewError(err), "Unable to parse time argument")
|
||||
}
|
||||
targetURL, err := getExpandedURL(url, config.Aliases)
|
||||
fatalIf(err)
|
||||
targetURL, err := getCanonicalizedURL(url, config.Aliases)
|
||||
fatalIf(err, "Unable to canonicalize URL")
|
||||
// if recursive strip off the "..."
|
||||
newTargetURL := stripRecursiveURL(targetURL)
|
||||
fatalIf(doShareCmd(newTargetURL, isURLRecursive(targetURL), expires))
|
||||
fatalIf(doShareCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL), expires), "Unable generate URL for sharing")
|
||||
}
|
||||
|
||||
func getNewTargetURL(targetParser *client.URL, name string) string {
|
||||
|
||||
+20
-22
@@ -60,34 +60,33 @@ func mainUpdate(ctx *cli.Context) {
|
||||
if ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
||||
}
|
||||
fatalIf(doUpdateCheck())
|
||||
}
|
||||
|
||||
func doUpdateCheck() *probe.Error {
|
||||
clnt, err := url2Client(mcUpdateURL)
|
||||
if err != nil {
|
||||
return err.Trace(mcUpdateURL)
|
||||
}
|
||||
fatalIf(err, "Unable to initalize update URL")
|
||||
|
||||
data, _, err := clnt.GetObject(0, 0)
|
||||
if err != nil {
|
||||
return err.Trace(mcUpdateURL)
|
||||
}
|
||||
current, _ := time.Parse(time.RFC3339Nano, Version)
|
||||
fatalIf(err, "Unable to read update URL")
|
||||
|
||||
current, goerr := time.Parse(time.RFC3339Nano, Version)
|
||||
fatalIf(probe.NewError(goerr), "Unable to parse Version as time")
|
||||
|
||||
if current.IsZero() {
|
||||
console.Infoln(`Version is empty, must be a custom build cannot update. Please download releases from
|
||||
https://dl.minio.io:9000 for continuous updates`)
|
||||
return nil
|
||||
return
|
||||
}
|
||||
var updates Updates
|
||||
decoder := json.NewDecoder(data)
|
||||
if err := decoder.Decode(&updates); err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
latest, _ := time.Parse(http.TimeFormat, updates.BuildDate)
|
||||
goerr = decoder.Decode(&updates)
|
||||
fatalIf(probe.NewError(goerr), "Unable to decode update URL data")
|
||||
|
||||
latest, goerr := time.Parse(http.TimeFormat, updates.BuildDate)
|
||||
fatalIf(probe.NewError(goerr), "Unable to parse BuildDate")
|
||||
|
||||
if latest.IsZero() {
|
||||
console.Infoln("No update available at this time")
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
mcUpdateURLParse := clnt.URL()
|
||||
if latest.After(current) {
|
||||
var updateString string
|
||||
@@ -97,12 +96,11 @@ https://dl.minio.io:9000 for continuous updates`)
|
||||
updateString = "mc cp " + mcUpdateURLParse.Scheme + "://" + mcUpdateURLParse.Host + string(mcUpdateURLParse.Separator) + updates.Platforms[runtime.GOOS] + " ./mc"
|
||||
}
|
||||
msg, err := printUpdateNotify(updateString, "new", "old")
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
fatalIf(probe.NewError(err), "Unable to print update notification")
|
||||
|
||||
console.Println(msg)
|
||||
return nil
|
||||
return
|
||||
}
|
||||
console.Infoln("You are already running the most recent version of ‘mc’")
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ func stripRecursiveURL(urlStr string) string {
|
||||
return urlStr
|
||||
}
|
||||
|
||||
// getExpandedURL - extracts URL string from a single cmd-line argument
|
||||
func getExpandedURL(arg string, aliases map[string]string) (urlStr string, err *probe.Error) {
|
||||
// getCanonicalizedURL - extracts URL string from a single cmd-line argument
|
||||
func getCanonicalizedURL(arg string, aliases map[string]string) (urlStr string, err *probe.Error) {
|
||||
// Check and expand Alias
|
||||
urlStr, err = aliasExpand(arg, aliases)
|
||||
if err != nil {
|
||||
@@ -59,10 +59,10 @@ func getExpandedURL(arg string, aliases map[string]string) (urlStr string, err *
|
||||
return urlStr, nil
|
||||
}
|
||||
|
||||
// getExpandedURLs - extracts multiple URL strings from a single cmd-line argument
|
||||
func getExpandedURLs(args []string, aliases map[string]string) (urls []string, err *probe.Error) {
|
||||
// getCanonicalizedURLs - extracts multiple URL strings from a single cmd-line argument
|
||||
func getCanonicalizedURLs(args []string, aliases map[string]string) (urls []string, err *probe.Error) {
|
||||
for _, arg := range args {
|
||||
u, err := getExpandedURL(arg, aliases)
|
||||
u, err := getCanonicalizedURL(arg, aliases)
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func args2URLs(args []string) ([]string, *probe.Error) {
|
||||
|
||||
}
|
||||
// Convert arguments to URLs: expand alias, fix format...
|
||||
URLs, err := getExpandedURLs(args, config.Aliases)
|
||||
URLs, err := getCanonicalizedURLs(args, config.Aliases)
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
|
||||
+5
-4
@@ -111,14 +111,15 @@ func verifyMCRuntime() {
|
||||
console.Fatalf("Unable to create ‘mc’ config folder. %s\n", err)
|
||||
}
|
||||
config, err := newConfig()
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to initialize newConfig")
|
||||
|
||||
err = writeConfig(config)
|
||||
fatalIf(err)
|
||||
fatalIf(err, "Unable to write newConfig")
|
||||
|
||||
console.Infoln("Configuration written to [" + mustGetMcConfigPath() + "]. Please update your access credentials.")
|
||||
}
|
||||
if !isSessionDirExists() {
|
||||
err := createSessionDir()
|
||||
fatalIf(err)
|
||||
fatalIf(createSessionDir(), "Unable to create session dir")
|
||||
}
|
||||
checkGolangRuntimeVersion()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user