1
0
mirror of https://github.com/minio/mc.git synced 2025-11-13 12:22:45 +03:00

console enhancements, consistent error message and janitor duty

This commit is contained in:
Anand Babu (AB) Periasamy
2015-04-23 21:13:59 -07:00
parent 4f2b4f9881
commit c09ce54090
56 changed files with 272 additions and 175 deletions

2
NOTICE
View File

@@ -1,4 +1,4 @@
Mini Copy, (C) 2014,2015 Minio, Inc. Mini Copy (C) 2014, 2015 Minio, Inc.
This product includes software developed at Minio, Inc. This product includes software developed at Minio, Inc.
(http://minio.io/). (http://minio.io/).

16
acl.go
View File

@@ -1,3 +1,19 @@
/*
* Mini Copy (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 package main
// isValidBucketACL - is provided acl string supported // isValidBucketACL - is provided acl string supported

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014, 2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Mini Copy, (C) 2015 Minio, Inc. # Mini Copy (C) 2015 Minio, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

16
buildscripts/git-commit-id.sh Normal file → Executable file
View File

@@ -1,4 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# Mini Copy (C) 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.
#
CONST_FILE=build-constants.go CONST_FILE=build-constants.go

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014, 2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014, 2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014, 2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -310,19 +310,19 @@ func doConfigCmd(ctx *cli.Context) {
configPath, err := getMcConfigPath() configPath, err := getMcConfigPath()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("mc: Unable to identify config file path") console.Fatalln("Unable to determine config file path.")
} }
err = saveConfig(ctx) err = saveConfig(ctx)
if err != nil { if err != nil {
switch iodine.ToError(err).(type) { switch iodine.ToError(err).(type) {
case errConfigExists: case errConfigExists:
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("mc: Configuration file " + configPath + " already exists") console.Fatalln("Configuration file " + configPath + " already exists.")
default: default:
// unexpected error // unexpected error
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("mc: Unable to generate config file", configPath) console.Fatalln("Unable to generate config file", configPath, ".")
} }
} }
console.Infoln("mc: Configuration written to " + configPath + ". Please update your access credentials.") console.Infoln("Configuration written to " + configPath + ". Please update your access credentials.")
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014, 2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package main package main
import ( import (
"fmt"
"strings" "strings"
"github.com/minio-io/mc/pkg/console" "github.com/minio-io/mc/pkg/console"
@@ -30,20 +29,22 @@ const (
) )
// doCopyCmdRecursive - copy bucket to bucket // doCopyCmdRecursive - copy bucket to bucket
func doCopyCmdRecursive(manager clientManager, sourceURLConfigMap map[string]*hostConfig, targetURLConfigMap map[string]*hostConfig) (string, error) { func doCopyCmdRecursive(manager clientManager, sourceURLConfigMap map[string]*hostConfig, targetURLConfigMap map[string]*hostConfig) error {
for sourceURL, sourceConfig := range sourceURLConfigMap { for sourceURL, sourceConfig := range sourceURLConfigMap {
// get source list // get source list
clnt, err := manager.getNewClient(sourceURL, sourceConfig, false) clnt, err := manager.getNewClient(sourceURL, sourceConfig, false)
if err != nil { if err != nil {
return fmt.Sprintf("instantiating a new client for URL [%s]", sourceURL), iodine.New(err, nil) return iodine.New(err, map[string]string{"Source": sourceURL})
} }
for itemCh := range clnt.List() { for itemCh := range clnt.List() {
if itemCh.Err != nil { if itemCh.Err != nil {
return fmt.Sprintf("listing objects failed for URL [%s]", sourceURL), iodine.New(itemCh.Err, nil) return iodine.New(err, map[string]string{"Source": sourceURL})
} }
if itemCh.Item.FileType.IsDir() { if itemCh.Item.FileType.IsDir() {
continue continue
} }
// populate source urls // populate source urls
sourceURLs := make(map[string]*hostConfig) sourceURLs := make(map[string]*hostConfig)
sourceObjectURL := itemCh.Item.Name sourceObjectURL := itemCh.Item.Name
@@ -54,13 +55,13 @@ func doCopyCmdRecursive(manager clientManager, sourceURLConfigMap map[string]*ho
targetObjectURL := strings.TrimSuffix(targetURL, pathSeparator) + pathSeparator + itemCh.Item.Name targetObjectURL := strings.TrimSuffix(targetURL, pathSeparator) + pathSeparator + itemCh.Item.Name
targetURLs[targetObjectURL] = targetConfig targetURLs[targetObjectURL] = targetConfig
} }
humanReadable, err := doCopyCmd(manager, sourceURLs, targetURLs) err := doCopyCmd(manager, sourceURLs, targetURLs)
if err != nil { if err != nil {
err := iodine.New(err, nil) err := iodine.New(err, nil)
log.Debug.Println(err) log.Debug.Println(err)
console.Errorln(humanReadable) console.Errorln("Failed to copy from %s to %s. Reason: [%s].\n", sourceURLs, targetURLs, iodine.ToError(err))
} }
} }
} }
return "", nil return nil
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014,2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package main package main
import ( import (
"fmt"
"io" "io"
"strings" "strings"
@@ -36,7 +35,7 @@ func runCopyCmd(ctx *cli.Context) {
config, err := getMcConfig() config, err := getMcConfig()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: loading config file failed with following reason: [%s]\n", iodine.ToError(err)) console.Fatalf("Unable to read config file [%s]. Reason: [%s].\n", mustGetMcConfigPath(), iodine.ToError(err))
} }
// Convert arguments to URLs: expand alias, fix format... // Convert arguments to URLs: expand alias, fix format...
@@ -45,10 +44,10 @@ func runCopyCmd(ctx *cli.Context) {
switch e := iodine.ToError(err).(type) { switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme: case errUnsupportedScheme:
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: reading URL [%s] failed with following reason: [%s]\n", e.url, e) console.Fatalf("Unknown type of URL(s).\n")
default: default:
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: reading URLs failed with following reason: [%s]\n", e) console.Fatalf("Unable to parse arguments. Reason: [%s].\n", e)
} }
} }
@@ -64,53 +63,48 @@ func runCopyCmd(ctx *cli.Context) {
sourceConfig, err := getHostConfig(sourceURL) sourceConfig, err := getHostConfig(sourceURL)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: reading host config for URL [%s] failed with following reason: [%s]\n", sourceURL, iodine.ToError(err)) console.Fatalf("Unable to read host configuration for source [%s] from config file [%s]. Reason: [%s].\n",
sourceURL, mustGetMcConfigPath(), iodine.ToError(err))
} }
sourceURLConfigMap[sourceURL] = sourceConfig sourceURLConfigMap[sourceURL] = sourceConfig
targetURLConfigMap, err := getHostConfigs(targetURLs) targetURLConfigMap, err := getHostConfigs(targetURLs)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: reading host configs failed with following reason: [%s]\n", iodine.ToError(err)) console.Fatalf("Unable to read host configuration for the following targets %s from config file [%s]. Reason: [%s].\n",
targetURLs, mustGetMcConfigPath(), iodine.ToError(err))
} }
// perform recursive // perform recursive
if recursive { if recursive {
errorMsg, err := doCopyCmdRecursive(mcClientManager{}, sourceURLConfigMap, targetURLConfigMap) err := doCopyCmdRecursive(mcClientManager{}, sourceURLConfigMap, targetURLConfigMap)
err = iodine.New(err, nil) err = iodine.New(err, nil)
if err != nil { if err != nil {
if errorMsg == "" {
errorMsg = "No error message present, please rerun with --debug and report a bug."
}
log.Debug.Println(err) log.Debug.Println(err)
console.Fatalf("mc: %s with following reason: [%s]\n", errorMsg, iodine.ToError(err)) console.Fatalf("Failed to copy recursively. Reason: [%s].\n", iodine.ToError(err))
} }
return return
} }
errorMsg, err := doCopyCmd(mcClientManager{}, sourceURLConfigMap, targetURLConfigMap) err = doCopyCmd(mcClientManager{}, sourceURLConfigMap, targetURLConfigMap)
err = iodine.New(err, nil) err = iodine.New(err, nil)
if err != nil { if err != nil {
if errorMsg == "" {
errorMsg = "No error message present, please rerun with --debug and report a bug."
}
log.Debug.Println(err) log.Debug.Println(err)
console.Fatalf("mc: %s with following reason: [%s]\n", errorMsg, iodine.ToError(err)) console.Fatalf("Failed to copy from source [%s] to target %s. Reason: [%s].\n", sourceURL, targetURLs, iodine.ToError(err))
} }
} }
// doCopyCmd copies objects into and from a bucket or between buckets // doCopyCmd copies objects into and from a bucket or between buckets
func doCopyCmd(manager clientManager, sourceURLConfigMap map[string]*hostConfig, targetURLConfigMap map[string]*hostConfig) (string, error) { func doCopyCmd(manager clientManager, sourceURLConfigMap map[string]*hostConfig, targetURLConfigMap map[string]*hostConfig) error {
for sourceURL, sourceConfig := range sourceURLConfigMap { for sourceURL, sourceConfig := range sourceURLConfigMap {
reader, length, hexMd5, err := manager.getSourceReader(sourceURL, sourceConfig) reader, length, hexMd5, err := manager.getSourceReader(sourceURL, sourceConfig)
if err != nil { if err != nil {
msg := fmt.Sprintf("Reading from source URL: [%s] failed", sourceURL) return iodine.New(err, map[string]string{"Source": sourceURL})
return msg, iodine.New(err, nil)
} }
defer reader.Close() defer reader.Close()
writeClosers, err := getTargetWriters(manager, targetURLConfigMap, hexMd5, length) writeClosers, err := getTargetWriters(manager, targetURLConfigMap, hexMd5, length)
if err != nil { if err != nil {
return "Writing to target URL failed", iodine.New(err, nil) return iodine.New(err, nil)
} }
var writers []io.Writer var writers []io.Writer
@@ -142,16 +136,16 @@ func doCopyCmd(manager clientManager, sourceURLConfigMap map[string]*hostConfig,
} }
// write copy errors if present // write copy errors if present
if copyErr != nil { if copyErr != nil {
return "Copying data from source to target(s) failed", iodine.New(copyErr, nil) return iodine.New(copyErr, map[string]string{"Source": sourceURL})
} }
// write close errors if present after checking copyErr // write close errors if present after checking copyErr
if err != nil { if err != nil {
return "Connections still active, one or more writes may of failed.", iodine.New(err, nil) return iodine.New(err, map[string]string{"Source": sourceURL})
} }
if !globalQuietFlag { if !globalQuietFlag {
bar.Finish() bar.Finish()
console.Infoln("Success!") // console.Infoln("Success!")
} }
} }
return "", nil return nil
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014,2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -17,9 +17,8 @@
package main package main
import ( import (
"time"
"fmt" "fmt"
"time"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/minio-io/cli" "github.com/minio-io/cli"
@@ -40,7 +39,7 @@ func printItem(date time.Time, v int64, name string) {
fmt.Println(console.File("%s", name)) fmt.Println(console.File("%s", name))
} }
func doList(clnt client.Client, targetURL string) (string, error) { func doList(clnt client.Client, targetURL string) error {
var err error var err error
for itemCh := range clnt.List() { for itemCh := range clnt.List() {
if itemCh.Err != nil { if itemCh.Err != nil {
@@ -49,12 +48,11 @@ func doList(clnt client.Client, targetURL string) (string, error) {
} }
printItem(itemCh.Item.Time, itemCh.Item.Size, itemCh.Item.Name) printItem(itemCh.Item.Time, itemCh.Item.Size, itemCh.Item.Name)
} }
if err != nil { if err != nil {
err = iodine.New(err, nil) return iodine.New(err, map[string]string{"Target": targetURL})
msg := fmt.Sprintf("mc: listing objects for URL [%s] failed with following reason: [%s]\n", targetURL, iodine.ToError(err))
return msg, err
} }
return "", nil return nil
} }
// runListCmd lists objects inside a bucket // runListCmd lists objects inside a bucket
@@ -65,7 +63,7 @@ func runListCmd(ctx *cli.Context) {
config, err := getMcConfig() config, err := getMcConfig()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: Error reading config file. Reason: %s\n", iodine.ToError(err)) console.Fatalf("Unable to read config file [%s]. Reason: [%s].\n", mustGetMcConfigPath(), iodine.ToError(err))
} }
targetURLConfigMap := make(map[string]*hostConfig) targetURLConfigMap := make(map[string]*hostConfig)
for _, arg := range ctx.Args() { for _, arg := range ctx.Args() {
@@ -74,39 +72,33 @@ func runListCmd(ctx *cli.Context) {
switch iodine.ToError(err).(type) { switch iodine.ToError(err).(type) {
case errUnsupportedScheme: case errUnsupportedScheme:
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: Unknown type of URL [%s].\n", arg) console.Fatalf("Unknown type of URL [%s].\n", arg)
default: default:
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: Unknown type of URL [%s]. Reason: %s\n", arg, iodine.ToError(err)) console.Fatalf("Unable to parse argument [%s]. Reason: [%s].\n", arg, iodine.ToError(err))
} }
} }
targetConfig, err := getHostConfig(targetURL) targetConfig, err := getHostConfig(targetURL)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: Error reading config for URL [%s]. Reason: %s\n", targetURL, iodine.ToError(err)) console.Fatalf("Unable to read host configuration for [%s] from config file [%s]. Reason: [%s].\n", targetURL, mustGetMcConfigPath(), iodine.ToError(err))
} }
targetURLConfigMap[targetURL] = targetConfig targetURLConfigMap[targetURL] = targetConfig
} }
for targetURL, targetConfig := range targetURLConfigMap { for targetURL, targetConfig := range targetURLConfigMap {
errorMsg, err := doListCmd(mcClientManager{}, targetURL, targetConfig, globalDebugFlag) err = doListCmd(mcClientManager{}, targetURL, targetConfig, globalDebugFlag)
err = iodine.New(err, nil) err = iodine.New(err, nil)
if err != nil { if err != nil {
if errorMsg == "" {
errorMsg = "mc: List command failed. Please re-run with --debug and report this bug."
}
log.Debug.Println(err) log.Debug.Println(err)
console.Errorf("%s", errorMsg) console.Fatalf("Failed to list [%s]. Reason: [%s].\n", targetURL, iodine.ToError(err))
} }
} }
} }
func doListCmd(manager clientManager, targetURL string, targetConfig *hostConfig, debug bool) (string, error) { func doListCmd(manager clientManager, targetURL string, targetConfig *hostConfig, debug bool) error {
clnt, err := manager.getNewClient(targetURL, targetConfig, globalDebugFlag) clnt, err := manager.getNewClient(targetURL, targetConfig, globalDebugFlag)
if err != nil { if err != nil {
err := iodine.New(err, nil) return iodine.New(err, map[string]string{"Target": targetURL})
msg := fmt.Sprintf("mc: instantiating a new client for URL [%s] failed with following reason: [%s]\n",
targetURL, iodine.ToError(err))
return msg, err
} }
return doList(clnt, targetURL) return doList(clnt, targetURL)
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014,2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ func runMakeBucketCmd(ctx *cli.Context) {
config, err := getMcConfig() config, err := getMcConfig()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("mc: Unable to read config") console.Fatalf("Unable to read config file [%s].\n", mustGetMcConfigPath())
} }
targetURLConfigMap := make(map[string]*hostConfig) targetURLConfigMap := make(map[string]*hostConfig)
targetURLs, err := getURLs(ctx.Args(), config.Aliases) targetURLs, err := getURLs(ctx.Args(), config.Aliases)
@@ -43,23 +43,23 @@ func runMakeBucketCmd(ctx *cli.Context) {
switch e := iodine.ToError(err).(type) { switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme: case errUnsupportedScheme:
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: reading URL [%s] failed with following reason: [%s]\n", e.url, e) console.Fatalf("Unknown URL type [%s] passed. Reason: [%s].\n", e.url, e)
default: default:
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: reading URLs failed with following reason: [%s]\n", e) console.Fatalf("Error in parsing path or URL. Reason: [%s].\n", e)
} }
} }
acl := bucketACL(ctx.Args().First()) acl := bucketACL(ctx.Args().First())
if !acl.isValidBucketACL() { if !acl.isValidBucketACL() {
log.Debug.Println(iodine.New(errInvalidACL{acl: acl.String()}, nil)) log.Debug.Println(iodine.New(errInvalidACL{acl: acl.String()}, nil))
console.Fatalf("mc: Unsupported type of acl requested [%s], supported types are [private, public-read, public-read-write]\n", acl) console.Fatalf("Access type [%s] is not supported. Valid types are [private, private, read-only].\n", acl)
} }
targetURLs = targetURLs[1:] // 1 or more target URLs targetURLs = targetURLs[1:] // 1 or more target URLs
for _, targetURL := range targetURLs { for _, targetURL := range targetURLs {
targetConfig, err := getHostConfig(targetURL) targetConfig, err := getHostConfig(targetURL)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: reading config URL [%s] failed with following reason: [%s]\n", targetURL, iodine.ToError(err)) console.Fatalf("Unable to read configuration for host [%s]. Reason: [%s].\n", targetURL, iodine.ToError(err))
} }
targetURLConfigMap[targetURL] = targetConfig targetURLConfigMap[targetURL] = targetConfig
} }
@@ -68,7 +68,7 @@ func runMakeBucketCmd(ctx *cli.Context) {
err = iodine.New(err, nil) err = iodine.New(err, nil)
if err != nil { if err != nil {
if errorMsg == "" { if errorMsg == "" {
errorMsg = "No error message present, please rerun with --debug and report a bug." errorMsg = "Empty error message. Please rerun this command with --debug and file a bug report."
} }
log.Debug.Println(err) log.Debug.Println(err)
console.Errorf("%s", errorMsg) console.Errorf("%s", errorMsg)
@@ -82,7 +82,7 @@ func doMakeBucketCmd(manager clientManager, targetURL, targetACL string, targetC
clnt, err = manager.getNewClient(targetURL, targetConfig, debug) clnt, err = manager.getNewClient(targetURL, targetConfig, debug)
if err != nil { if err != nil {
err := iodine.New(err, nil) err := iodine.New(err, nil)
msg := fmt.Sprintf("mc: instantiating a new client for URL [%s] failed with following reason: [%s]\n", msg := fmt.Sprintf("Unable to initialize client for [%s]. Reason: [%s].\n",
targetURL, iodine.ToError(err)) targetURL, iodine.ToError(err))
return msg, err return msg, err
} }
@@ -102,7 +102,7 @@ func doMakeBucket(clnt client.Client, targetURL, targetACL string) (string, erro
} }
if err != nil { if err != nil {
err := iodine.New(err, nil) err := iodine.New(err, nil)
msg := fmt.Sprintf("\nmc: Creating bucket failed for URL [%s] with following reason: [%s]\n", targetURL, iodine.ToError(err)) msg := fmt.Sprintf("Failed to create bucket for URL [%s]. Reason: [%s].\n", targetURL, iodine.ToError(err))
return msg, err return msg, err
} }
return "", nil return "", nil

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014,2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014, 2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -80,8 +80,7 @@ func (s *CmdTestSuite) TestCopyToSingleTarget(c *C) {
manager.On("getSourceReader", sourceURL, sourceConfig).Return(sourceReader, dataLength, hexMd5, nil).Once() manager.On("getSourceReader", sourceURL, sourceConfig).Return(sourceReader, dataLength, hexMd5, nil).Once()
manager.On("getTargetWriter", targetURL, targetConfig, hexMd5, dataLength).Return(targetWriter, nil).Once() manager.On("getTargetWriter", targetURL, targetConfig, hexMd5, dataLength).Return(targetWriter, nil).Once()
msg, err := doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap)
c.Assert(msg, Equals, "")
c.Assert(err, IsNil) c.Assert(err, IsNil)
wg.Wait() wg.Wait()
c.Assert(err, IsNil) c.Assert(err, IsNil)
@@ -165,8 +164,7 @@ func (s *CmdTestSuite) TestCopyRecursive(c *C) {
manager.On("getSourceReader", "hello2", sourceConfig).Return(sourceReader2, dataLen2, etag2, nil).Once() manager.On("getSourceReader", "hello2", sourceConfig).Return(sourceReader2, dataLen2, etag2, nil).Once()
manager.On("getTargetWriter", targetURL+"hello2", targetConfig, etag2, dataLen2).Return(writer2, nil).Once() manager.On("getTargetWriter", targetURL+"hello2", targetConfig, etag2, dataLen2).Return(writer2, nil).Once()
msg, err := doCopyCmdRecursive(manager, sourceURLConfigMap, targetURLConfigMap) err = doCopyCmdRecursive(manager, sourceURLConfigMap, targetURLConfigMap)
c.Assert(msg, Equals, "")
c.Assert(err, IsNil) c.Assert(err, IsNil)
wg.Wait() wg.Wait()
@@ -202,8 +200,7 @@ func (s *CmdTestSuite) TestCopyCmdFailures(c *C) {
targetURLConfigMap[targetURL] = targetConfig targetURLConfigMap[targetURL] = targetConfig
manager.On("getSourceReader", sourceURL, sourceConfig).Return(nilReadCloser, int64(0), "", errors.New("Expected Error")).Once() manager.On("getSourceReader", sourceURL, sourceConfig).Return(nilReadCloser, int64(0), "", errors.New("Expected Error")).Once()
msg, err := doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap)
c.Assert(len(msg) > 0, Equals, true)
c.Assert(err, Not(IsNil)) c.Assert(err, Not(IsNil))
manager.AssertExpectations(c) manager.AssertExpectations(c)
@@ -217,10 +214,9 @@ func (s *CmdTestSuite) TestCopyCmdFailures(c *C) {
manager.On("getSourceReader", sourceURL, sourceConfig).Return(reader1, dataLen1, etag1, nil).Once() manager.On("getSourceReader", sourceURL, sourceConfig).Return(reader1, dataLen1, etag1, nil).Once()
manager.On("getTargetWriter", targetURL, targetConfig, etag1, dataLen1).Return(nil, errors.New("Expected Error")).Once() manager.On("getTargetWriter", targetURL, targetConfig, etag1, dataLen1).Return(nil, errors.New("Expected Error")).Once()
msg, err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap)
writer1.Close() writer1.Close()
wg.Wait() wg.Wait()
c.Assert(len(msg) > 0, Equals, true)
c.Assert(err, Not(IsNil)) c.Assert(err, Not(IsNil))
// target write fails // target write fails
@@ -242,9 +238,8 @@ func (s *CmdTestSuite) TestCopyCmdFailures(c *C) {
}() }()
manager.On("getSourceReader", sourceURL, sourceConfig).Return(reader2, dataLen1, etag1, nil).Once() manager.On("getSourceReader", sourceURL, sourceConfig).Return(reader2, dataLen1, etag1, nil).Once()
manager.On("getTargetWriter", targetURL, targetConfig, etag1, dataLen1).Return(writer3, nil).Once() manager.On("getTargetWriter", targetURL, targetConfig, etag1, dataLen1).Return(writer3, nil).Once()
msg, err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap)
wg.Wait() wg.Wait()
c.Assert(len(msg) > 0, Equals, true)
c.Assert(err, Not(IsNil)) c.Assert(err, Not(IsNil))
c.Assert(n3, Equals, int64(3)) c.Assert(n3, Equals, int64(3))
@@ -259,9 +254,8 @@ func (s *CmdTestSuite) TestCopyCmdFailures(c *C) {
failClose = &FailClose{} failClose = &FailClose{}
manager.On("getSourceReader", sourceURL, sourceConfig).Return(reader4, dataLen1, etag1, nil).Once() manager.On("getSourceReader", sourceURL, sourceConfig).Return(reader4, dataLen1, etag1, nil).Once()
manager.On("getTargetWriter", targetURL, targetConfig, etag1, dataLen1).Return(failClose, nil).Once() manager.On("getTargetWriter", targetURL, targetConfig, etag1, dataLen1).Return(failClose, nil).Once()
msg, err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap)
wg.Wait() wg.Wait()
c.Assert(len(msg) > 0, Equals, true)
c.Assert(err, Not(IsNil)) c.Assert(err, Not(IsNil))
} }
@@ -310,8 +304,7 @@ func (s *CmdTestSuite) TestLsCmdWithBucket(c *C) {
} }
}() }()
cl1.On("List").Return(itemCh).Once() cl1.On("List").Return(itemCh).Once()
msg, err := doListCmd(manager, sourceURL, sourceConfig, false) err = doListCmd(manager, sourceURL, sourceConfig, false)
c.Assert(msg, Equals, "")
c.Assert(err, IsNil) c.Assert(err, IsNil)
manager.AssertExpectations(c) manager.AssertExpectations(c)
@@ -343,6 +336,7 @@ func (s *CmdTestSuite) TestLsCmdWithFilePath(c *C) {
sourceURLConfigMap[sourceURL] = sourceConfig sourceURLConfigMap[sourceURL] = sourceConfig
manager.On("getNewClient", sourceURL, sourceConfig, false).Return(cl1, nil).Once() manager.On("getNewClient", sourceURL, sourceConfig, false).Return(cl1, nil).Once()
itemCh := make(chan client.ItemOnChannel) itemCh := make(chan client.ItemOnChannel)
go func() { go func() {
defer close(itemCh) defer close(itemCh)
@@ -354,8 +348,7 @@ func (s *CmdTestSuite) TestLsCmdWithFilePath(c *C) {
} }
}() }()
cl1.On("List").Return(itemCh).Once() cl1.On("List").Return(itemCh).Once()
msg, err := doListCmd(manager, sourceURL, sourceConfig, false) err = doListCmd(manager, sourceURL, sourceConfig, false)
c.Assert(msg, Equals, "")
c.Assert(err, IsNil) c.Assert(err, IsNil)
manager.AssertExpectations(c) manager.AssertExpectations(c)
@@ -392,8 +385,7 @@ func (s *CmdTestSuite) TestLsCmdListsBuckets(c *C) {
} }
}() }()
cl1.On("List").Return(itemCh).Once() cl1.On("List").Return(itemCh).Once()
msg, err := doListCmd(manager, sourceURL, sourceConfig, false) err = doListCmd(manager, sourceURL, sourceConfig, false)
c.Assert(msg, Equals, "")
c.Assert(err, IsNil) c.Assert(err, IsNil)
manager.AssertExpectations(c) manager.AssertExpectations(c)

2
doc.go
View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014,2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014,2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

16
main.go
View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2014, 2015 Minio, Inc. * Mini Copy (C) 2014, 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -31,12 +31,12 @@ import (
"github.com/minio-io/minio/pkg/utils/log" "github.com/minio-io/minio/pkg/utils/log"
) )
func checkConfig() {
// Check for the environment early on and gracefuly report. // Check for the environment early on and gracefuly report.
func checkConfig() {
_, err := user.Current() _, err := user.Current()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("mc: Unable to obtain user's home directory") console.Fatalln("Unable to determine user's home directory")
} }
// If config doesn't exist, do not attempt to read it // If config doesn't exist, do not attempt to read it
@@ -48,11 +48,11 @@ func checkConfig() {
_, err = getMcConfig() _, err = getMcConfig()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("mc: Unable to read config file: %s\n", mustGetMcConfigPath()) console.Fatalf("Unable to read config file: %s\n", mustGetMcConfigPath())
} }
} }
// Tries to get os/arch/platform specific information // Get os/arch/platform specific information.
// Returns a map of current os/arch/platform/memstats // Returns a map of current os/arch/platform/memstats
func getSystemData() map[string]string { func getSystemData() map[string]string {
host, err := os.Hostname() host, err := os.Hostname()
@@ -100,17 +100,17 @@ func main() {
if console.IsValidTheme(themeName) { if console.IsValidTheme(themeName) {
err := console.SetTheme(themeName) err := console.SetTheme(themeName)
if err != nil { if err != nil {
console.Fatalf("mc: failed to set theme [%s] with following reason: [%s]\n", themeName, iodine.ToError(err)) console.Fatalf("Failed to set theme [%s]. Reason: [%s].\n", themeName, iodine.ToError(err))
} }
} else { } else {
console.Fatalf("mc: Theme [%s] is not supported. Please choose from this list: %s\n", themeName, console.GetThemeNames()) console.Fatalf("Theme [%s] is not supported. Please choose from this list: %s.\n", themeName, console.GetThemeNames())
} }
checkConfig() checkConfig()
return nil return nil
} }
app.After = func(ctx *cli.Context) error { app.After = func(ctx *cli.Context) error {
if !isMcConfigExist() && ctx.Command.Name != "config" { if !isMcConfigExist() && ctx.Command.Name != "config" {
console.Fatalln("mc: error ``mc`` is not configured. Please run \"mc config generate\".") console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".")
} }
return nil return nil
} }

View File

@@ -1,3 +1,19 @@
/*
* Mini Copy (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 package main
import ( import (

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,19 @@
/*
* Mini Copy (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this fs 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 fs package fs
// GenericFileError - generic file error // GenericFileError - generic file error

View File

@@ -1,7 +1,7 @@
// +build darwin drangofly freebsd linux nacl netbsd openbsd solaris // +build darwin drangofly freebsd linux nacl netbsd openbsd solaris
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this fs except in compliance with the License. * you may not use this fs except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this fs except in compliance with the License. * you may not use this fs except in compliance with the License.

View File

@@ -1,7 +1,7 @@
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this fs except in compliance with the License. * you may not use this fs except in compliance with the License.

View File

@@ -1,7 +1,7 @@
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this fs except in compliance with the License. * you may not use this fs except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this fs except in compliance with the License. * you may not use this fs except in compliance with the License.

View File

@@ -21,7 +21,7 @@ limitations under the License.
// ---------------------------------------- // // ---------------------------------------- //
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -21,7 +21,7 @@ limitations under the License.
// ---------------------------------------- // // ---------------------------------------- //
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -21,7 +21,7 @@ limitations under the License.
// ---------------------------------------- // // ---------------------------------------- //
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -21,7 +21,7 @@ limitations under the License.
// ---------------------------------------- // // ---------------------------------------- //
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -21,7 +21,7 @@ limitations under the License.
// ---------------------------------------- // // ---------------------------------------- //
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -21,7 +21,7 @@ limitations under the License.
// ---------------------------------------- // // ---------------------------------------- //
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this fs except in compliance with the License. * you may not use this fs except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,19 @@
/*
* Mini Copy (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 client package client
import "net/url" import "net/url"

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@ import (
"runtime" "runtime"
"sync" "sync"
"path/filepath"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/minio-io/minio/pkg/iodine" "github.com/minio-io/minio/pkg/iodine"
) )
@@ -35,30 +37,36 @@ var (
// currTheme is current theme // currTheme is current theme
currThemeName = GetDefaultThemeName() currThemeName = GetDefaultThemeName()
// Fatal prints a fatal message and exits // Fatal prints a error message and exits
Fatal = func(a ...interface{}) { themesDB[currThemeName].Fatal.Print(a...); os.Exit(1) } Fatal = func(a ...interface{}) { print(themesDB[currThemeName].Fatal, "<FATAL>", a...); os.Exit(1) }
// Fatalln prints a fatal message with a new line and exits // Fatalln prints a error message with a new line and exits
Fatalln = func(a ...interface{}) { themesDB[currThemeName].Fatal.Println(a...); os.Exit(1) } Fatalln = func(a ...interface{}) { println(themesDB[currThemeName].Fatal, "<FATAL>", a...); os.Exit(1) }
// Fatalf prints a fatal message with formatting and exits // Fatalf prints a error message with formatting and exits
Fatalf = func(f string, a ...interface{}) { themesDB[currThemeName].Fatal.Printf(f, a...); os.Exit(1) } Fatalf = func(f string, a ...interface{}) {
printf(themesDB[currThemeName].Fatal, "<FATAL>", f, a...)
os.Exit(1)
}
// Error prints a error message // Error prints a error message
Error = func(a ...interface{}) { themesDB[currThemeName].Error.Print(a...) } Error = func(a ...interface{}) { print(themesDB[currThemeName].Error, "<ERROR>", a...) }
// Errorln prints a error message with a new line // Errorln prints a error message with a new line
Errorln = func(a ...interface{}) { themesDB[currThemeName].Error.Println(a...) } Errorln = func(a ...interface{}) { println(themesDB[currThemeName].Error, "<ERROR>", a...) }
// Errorf prints a error message with formatting // Errorf prints a error message with formatting
Errorf = func(f string, a ...interface{}) { themesDB[currThemeName].Error.Printf(f, a...) } Errorf = func(f string, a ...interface{}) { printf(themesDB[currThemeName].Error, "<ERROR>", f, a...) }
// Info prints a informational message // Info prints a informational message
Info = func(a ...interface{}) { themesDB[currThemeName].Info.Print(a...) } Info = func(a ...interface{}) { print(themesDB[currThemeName].Info, "", a...) }
// Infoln prints a informational message with a new line // Infoln prints a informational message with a new line
Infoln = func(a ...interface{}) { themesDB[currThemeName].Info.Println(a...) } Infoln = func(a ...interface{}) { println(themesDB[currThemeName].Info, "", a...) }
// Infof prints a informational message with formatting // Infof prints a informational message with formatting
Infof = func(f string, a ...interface{}) { themesDB[currThemeName].Info.Printf(f, a...) } Infof = func(f string, a ...interface{}) { printf(themesDB[currThemeName].Info, "", f, a...) }
// Debug prints a debug message // Debug prints a debug message
Debug = func(a ...interface{}) { themesDB[currThemeName].Debug.Print(a...) } Debug = func(a ...interface{}) { print(themesDB[currThemeName].Debug, "<DEBUG>", a...) }
// Debugln prints a debug message with a new line // Debugln prints a debug message with a new line
Debugln = func(a ...interface{}) { themesDB[currThemeName].Debug.Println(a...) } Debugln = func(a ...interface{}) { println(themesDB[currThemeName].Debug, "<DEBUG>", a...) }
// Debugf prints a debug message with formatting // Debugf prints a debug message with formatting
Debugf = func(f string, a ...interface{}) { themesDB[currThemeName].Debug.Printf(f, a...) } Debugf = func(f string, a ...interface{}) { printf(themesDB[currThemeName].Debug, "<DEBUG>", f, a...) }
// File - File("foo.txt") // File - File("foo.txt")
File = themesDB[currThemeName].File.SprintfFunc() File = themesDB[currThemeName].File.SprintfFunc()
@@ -82,13 +90,29 @@ type Theme struct {
var ( var (
// wrap around standard fmt functions // wrap around standard fmt functions
print = func(a ...interface{}) { fmt.Print(a...) } // print prints a message prefixed with message type and program name
println = func(a ...interface{}) { fmt.Println(a...) } print = func(c *color.Color, prefix string, a ...interface{}) {
printf = func(f string, a ...interface{}) { fmt.Printf(f, a...) } mutex.Lock()
c.Printf(ProgramName()+": %s ", prefix)
c.Print(a...)
mutex.Unlock()
}
fatalPrint = func(a ...interface{}) { fmt.Print(a...); os.Exit(1) } // println - same as print with a new line
fatalPrintln = func(a ...interface{}) { fmt.Println(a...); os.Exit(1) } println = func(c *color.Color, prefix string, a ...interface{}) {
fatalPrintf = func(f string, a ...interface{}) { fmt.Printf(f, a...); os.Exit(1) } mutex.Lock()
c.Printf(ProgramName()+": %s ", prefix)
c.Println(a...)
mutex.Unlock()
}
// printf - same as print, but takes a format specifier
printf = func(c *color.Color, prefix string, f string, a ...interface{}) {
mutex.Lock()
c.Printf(ProgramName()+": %s ", prefix)
c.Printf(f, a...)
mutex.Unlock()
}
) )
// SetTheme sets a color theme // SetTheme sets a color theme
@@ -98,6 +122,7 @@ func SetTheme(themeName string) error {
} }
mutex.Lock() mutex.Lock()
currThemeName = themeName currThemeName = themeName
theme := themesDB[currThemeName] theme := themesDB[currThemeName]
@@ -109,18 +134,26 @@ func SetTheme(themeName string) error {
color.NoColor = false color.NoColor = false
} }
Fatal = func(a ...interface{}) { theme.Fatal.Print(a...); os.Exit(1) } // Error prints a error message
Fatalln = func(a ...interface{}) { theme.Fatal.Println(a...); os.Exit(1) } Error = func(a ...interface{}) { print(theme.Error, "<ERROR>", a...) }
Fatalf = func(f string, a ...interface{}) { theme.Fatal.Printf(f, a...); os.Exit(1) } // Errorln prints a error message with a new line
Error = func(a ...interface{}) { theme.Error.Print(a...) } Errorln = func(a ...interface{}) { println(theme.Error, "<ERROR>", a...) }
Errorln = func(a ...interface{}) { theme.Error.Println(a...) } // Errorf prints a error message with formatting
Errorf = func(f string, a ...interface{}) { theme.Error.Printf(f, a...) } Errorf = func(f string, a ...interface{}) { printf(theme.Error, "<ERROR>", f, a...) }
Info = func(a ...interface{}) { theme.Info.Print(a...) }
Infoln = func(a ...interface{}) { theme.Info.Println(a...) } // Info prints a informational message
Infof = func(f string, a ...interface{}) { theme.Info.Printf(f, a...) } Info = func(a ...interface{}) { print(theme.Info, "", a...) }
Debug = func(a ...interface{}) { theme.Debug.Print(a...) } // Infoln prints a informational message with a new line
Debugln = func(a ...interface{}) { theme.Debug.Println(a...) } Infoln = func(a ...interface{}) { println(theme.Info, "", a...) }
Debugf = func(f string, a ...interface{}) { theme.Debug.Printf(f, a...) } // Infof prints a informational message with formatting
Infof = func(f string, a ...interface{}) { printf(theme.Info, "", f, a...) }
// Debug prints a debug message
Debug = func(a ...interface{}) { print(theme.Debug, "<DEBUG>", a...) }
// Debugln prints a debug message with a new line
Debugln = func(a ...interface{}) { println(theme.Debug, "<DEBUG>", a...) }
// Debugf prints a debug message with formatting
Debugf = func(f string, a ...interface{}) { printf(theme.Debug, "<DEBUG>", f, a...) }
File = theme.File.SprintfFunc() File = theme.File.SprintfFunc()
Size = theme.Size.SprintfFunc() Size = theme.Size.SprintfFunc()
@@ -146,7 +179,6 @@ func GetDefaultThemeName() string {
// GetThemeNames returns currently supported list of themes // GetThemeNames returns currently supported list of themes
func GetThemeNames() (themeNames []string) { func GetThemeNames() (themeNames []string) {
for themeName := range themesDB { for themeName := range themesDB {
themeNames = append(themeNames, themeName) themeNames = append(themeNames, themeName)
} }
@@ -158,3 +190,9 @@ func IsValidTheme(themeName string) bool {
_, ok := themesDB[themeName] _, ok := themesDB[themeName]
return ok return ok
} }
// ProgramName - return the name of the executable program
func ProgramName() string {
_, progName := filepath.Split(os.Args[0])
return progName
}

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ var MiniTheme = Theme{
}*/ }*/
var MiniTheme = Theme{ var MiniTheme = Theme{
Debug: (color.New(color.FgWhite, color.Faint, color.Italic)), Debug: (color.New(color.FgWhite, color.Faint, color.Italic)),
Fatal: (color.New(color.FgRed, color.Italic)), Fatal: (color.New(color.FgRed, color.Italic, color.Bold)),
Error: (color.New(color.FgYellow, color.Italic)), Error: (color.New(color.FgYellow, color.Italic)),
Info: (color.New(color.FgGreen, color.Bold)), Info: (color.New(color.FgGreen, color.Bold)),
File: (color.New(color.FgWhite)), File: (color.New(color.FgWhite)),

View File

@@ -1,7 +1,7 @@
/* /*
* Quick - Quick key value store for config files and persistent state files * Quick - Quick key value store for config files and persistent state files
* *
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
/* /*
* Quick - Quick key value store for config files and persistent state files * Quick - Quick key value store for config files and persistent state files
* *
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

2
url.go
View File

@@ -1,5 +1,5 @@
/* /*
* Mini Copy, (C) 2015 Minio, Inc. * Mini Copy (C) 2015 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.