error messages and tiny bug fixes
This commit is contained in:
+3
-3
@@ -33,7 +33,7 @@ var accessCmd = cli.Command{
|
||||
mc {{.Name}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} PERMISSION TARGET [TARGET...] {{if .Description}}
|
||||
mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} PERMISSION TARGET [TARGET ...] {{if .Description}}
|
||||
|
||||
DESCRIPTION:
|
||||
{{.Description}}{{end}}{{if .Flags}}
|
||||
@@ -71,8 +71,8 @@ func mainAccess(ctx *cli.Context) {
|
||||
}
|
||||
for _, arg := range ctx.Args().Tail() {
|
||||
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
|
||||
fatalIf(err.Trace(arg), "Unable to parse URL argument ‘"+arg+"’.")
|
||||
fatalIf(doUpdateAccessCmd(targetURL, acl).Trace(targetURL), "Unable to set access permission ‘"+acl.String()+"’ for URL ‘"+targetURL+"’.")
|
||||
fatalIf(err.Trace(arg), "Unable to parse argument ‘"+arg+"’.")
|
||||
fatalIf(doUpdateAccessCmd(targetURL, acl).Trace(targetURL), "Unable to set access permission ‘"+acl.String()+"’ for ‘"+targetURL+"’.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Minio Client (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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
// AliasMessage container for content message structure
|
||||
type AliasMessage struct {
|
||||
Alias string `json:"alias"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// String string printer for Content metadata
|
||||
func (a AliasMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
message := console.Colorize("Alias", fmt.Sprintf("[%s] <-", a.Alias))
|
||||
message += console.Colorize("URL", fmt.Sprintf("%s", a.URL))
|
||||
return message + "\n"
|
||||
}
|
||||
jsonMessageBytes, err := json.Marshal(a)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(jsonMessageBytes) + "\n"
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -58,6 +59,26 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// AliasMessage container for content message structure
|
||||
type AliasMessage struct {
|
||||
Alias string `json:"alias"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// String string printer for Content metadata
|
||||
func (a AliasMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
message := console.Colorize("Alias", fmt.Sprintf("[%s] <-", a.Alias))
|
||||
message += console.Colorize("URL", fmt.Sprintf("%s", a.URL))
|
||||
return message + "\n"
|
||||
}
|
||||
jsonMessageBytes, err := json.Marshal(a)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(jsonMessageBytes) + "\n"
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Minio Client (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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/minio/minio/pkg/probe"
|
||||
)
|
||||
|
||||
// CopyMessage container for file copy messages
|
||||
type CopyMessage struct {
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
Length int64 `json:"length"`
|
||||
}
|
||||
|
||||
// String string printer for copy message
|
||||
func (c CopyMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("‘%s’ -> ‘%s’\n", c.Source, c.Target)
|
||||
}
|
||||
copyMessageBytes, err := json.Marshal(c)
|
||||
fatalIf(probe.NewError(err), "Failed to marshal copy message.")
|
||||
|
||||
return string(copyMessageBytes) + "\n"
|
||||
}
|
||||
+18
@@ -68,6 +68,24 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// CopyMessage container for file copy messages
|
||||
type CopyMessage struct {
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
Length int64 `json:"length"`
|
||||
}
|
||||
|
||||
// String string printer for copy message
|
||||
func (c CopyMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("‘%s’ -> ‘%s’\n", c.Source, c.Target)
|
||||
}
|
||||
copyMessageBytes, err := json.Marshal(c)
|
||||
fatalIf(probe.NewError(err), "Failed to marshal copy message.")
|
||||
|
||||
return string(copyMessageBytes) + "\n"
|
||||
}
|
||||
|
||||
// doCopy - Copy a singe file from source to destination
|
||||
func doCopy(cpURLs copyURLs, bar *barSend, cpQueue <-chan bool, wg *sync.WaitGroup, statusCh chan<- copyURLs) {
|
||||
defer wg.Done() // Notify that this copy routine is done.
|
||||
|
||||
@@ -82,7 +82,7 @@ func checkCopySyntax(ctx *cli.Context) {
|
||||
}
|
||||
if url.Host != "" {
|
||||
if url.Path == string(url.Separator) {
|
||||
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Bucket creation detected for %s, cloud storage URL's should use ‘mc mb’ to create buckets.", tgtURL))
|
||||
fatalIf(probe.NewError(errInvalidArgument), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -59,15 +59,15 @@ func mainDiff(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
config := mustGetMcConfig()
|
||||
firstURL := ctx.Args().First()
|
||||
secondURL := ctx.Args()[1]
|
||||
firstArg := ctx.Args().First()
|
||||
secondArg := ctx.Args()[1]
|
||||
|
||||
var err *probe.Error
|
||||
firstURL, err = getCanonicalizedURL(firstURL, config.Aliases)
|
||||
fatalIf(err.Trace(firstURL), "Unable to canonicalize first URL.")
|
||||
firstURL, err := getCanonicalizedURL(firstArg, config.Aliases)
|
||||
fatalIf(err.Trace(firstArg), "Unable to parse first argument ‘"+firstArg+"’.")
|
||||
|
||||
secondURL, err = getCanonicalizedURL(secondURL, config.Aliases)
|
||||
fatalIf(err.Trace(secondURL), "Unable to canonicalize second URL.")
|
||||
secondURL, err := getCanonicalizedURL(secondArg, config.Aliases)
|
||||
fatalIf(err.Trace(secondArg), "Unable to parse second argument ‘"+secondArg+"’.")
|
||||
|
||||
if isURLRecursive(secondURL) {
|
||||
fatalIf(probe.NewError(errInvalidArgument), "Second argument ‘"+secondURL+"’ cannot be recursive.")
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,24 +0,0 @@
|
||||
#### access
|
||||
|
||||
```go
|
||||
Name:
|
||||
mc access - Set access permissions
|
||||
|
||||
USAGE:
|
||||
mc access PERMISSION TARGET [TARGET...]
|
||||
|
||||
EXAMPLES:
|
||||
|
||||
1. Set bucket to "private" on Amazon S3 cloud storage.
|
||||
$ mc access private https://s3.amazonaws.com/burningman2011
|
||||
|
||||
2. Set bucket to "public" on Amazon S3 cloud storage.
|
||||
$ mc access public https://s3.amazonaws.com/shared
|
||||
|
||||
3. Set bucket to "authenticated" on Amazon S3 cloud storage to provide read access to IAM Authenticated Users group.
|
||||
$ mc access authenticated https://s3.amazonaws.com/shared-authenticated
|
||||
|
||||
4. Set folder to world readwrite (chmod 777) on local filesystem.
|
||||
$ mc access public /shared/Music
|
||||
|
||||
```
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
#### cat
|
||||
|
||||
```go
|
||||
NAME:
|
||||
mc cat - Display contents of a file
|
||||
|
||||
USAGE:
|
||||
mc cat SOURCE [SOURCE...]
|
||||
|
||||
EXAMPLES:
|
||||
1. Concantenate an object from Amazon S3 cloud storage to mplayer standard input.
|
||||
$ mc cat https://s3.amazonaws.com/ferenginar/klingon_opera_aktuh_maylotah.ogg | mplayer -
|
||||
|
||||
2. Concantenate a file from local filesystem to standard output.
|
||||
$ mc cat khitomer-accords.txt
|
||||
|
||||
3. Concantenate multiple files from local filesystem to standard output.
|
||||
$ mc cat *.txt > newfile.txt
|
||||
|
||||
4. Concatenate a non english file name from Amazon S3 cloud storage.
|
||||
$ mc cat s3:andoria/本語 > /tmp/本語
|
||||
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
#### config
|
||||
|
||||
```go
|
||||
NAME:
|
||||
mc config - Add new alias to default configuration "~/.mc/config.json" file.
|
||||
|
||||
USAGE:
|
||||
mc config alias NAME HOSTURL
|
||||
|
||||
EXAMPLES:
|
||||
1. Add alias URLs
|
||||
$ mc config alias zek https://s3.amazonaws.com/
|
||||
```
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
#### cp
|
||||
|
||||
```go
|
||||
NAME:
|
||||
mc cp - Copy files and folders from many sources to a single destination
|
||||
|
||||
USAGE:
|
||||
mc cp SOURCE [SOURCE...] TARGET
|
||||
|
||||
EXAMPLES:
|
||||
1. Copy list of objects from local file system to Amazon S3 cloud storage.
|
||||
$ mc cp Music/*.ogg https://s3.amazonaws.com/jukebox/
|
||||
|
||||
2. Copy a bucket recursively from Minio cloud storage to Amazon S3 cloud storage.
|
||||
$ mc cp https://play.minio.io:9000/photos/burningman2011... https://s3.amazonaws.com/private-photos/burningman/
|
||||
|
||||
3. Copy multiple local folders recursively to Minio cloud storage.
|
||||
$ mc cp backup/2014/... backup/2015/... https://play.minio.io:9000/archive/
|
||||
|
||||
4. Copy a bucket recursively from aliased Amazon S3 cloud storage to local filesystem on Windows.
|
||||
$ mc cp s3:documents/2014/... C:\backup\2014
|
||||
|
||||
5. Copy an object of non english characters to Amazon S3 cloud storage.
|
||||
$ mc cp 本語 s3:andoria/本語
|
||||
|
||||
```
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
#### ls
|
||||
|
||||
```go
|
||||
NAME:
|
||||
mc ls - List files and folders
|
||||
|
||||
USAGE:
|
||||
mc ls TARGET [TARGET...]
|
||||
|
||||
EXAMPLES:
|
||||
1. List objects recursively on Minio cloud storage.
|
||||
$ mc ls https://play.minio.io:9000/backup/...
|
||||
[2015-03-28 12:47:50 PDT] 34MiB 2006-Jan-1/backup.tar.gz
|
||||
[2015-03-31 14:46:33 PDT] 55MiB 2006-Mar-1/backup.tar.gz
|
||||
|
||||
2. List buckets on Amazon S3 cloud storage.
|
||||
$ mc ls https://s3.amazonaws.com/
|
||||
[2015-01-20 15:42:00 PST] 0B rom/
|
||||
[2015-01-15 00:05:40 PST] 0B zek/
|
||||
|
||||
3. List buckets from Amazon S3 cloud storage and recursively list objects from Minio cloud storage.
|
||||
$ mc ls https://s3.amazonaws.com/ https://play.minio.io:9000/backup/...
|
||||
2015-01-15 00:05:40 PST 0B zek/
|
||||
2015-03-31 14:46:33 PDT 55MiB 2006-Mar-1/backup.tar.gz
|
||||
|
||||
4. List files recursively on local filesystem on Windows.
|
||||
$ mc ls C:\Users\Worf\...
|
||||
[2015-03-28 12:47:50 PDT] 11.00MiB Martok\Klingon Council Ministers.pdf
|
||||
[2015-03-31 14:46:33 PDT] 15.00MiB Gowron\Khitomer Conference Details.pdf
|
||||
|
||||
5. List files with non english characters on Amazon S3 cloud storage.
|
||||
$ mc ls s3:andoria/本...
|
||||
[2015-05-19 17:21:49 PDT] 41B 本語.pdf
|
||||
[2015-05-19 17:24:19 PDT] 41B 本語.txt
|
||||
[2015-05-19 17:28:22 PDT] 41B 本語.md
|
||||
|
||||
```
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
#### mb
|
||||
|
||||
```go
|
||||
NAME:
|
||||
mc mb - Make a bucket or folder
|
||||
|
||||
USAGE:
|
||||
mc mb TARGET [TARGET...]
|
||||
|
||||
EXAMPLES:
|
||||
1. Create a bucket on Amazon S3 cloud storage.
|
||||
$ mc mb https://s3.amazonaws.com/public-document-store
|
||||
|
||||
3. Make a folder on local filesystem, including its parent folders as needed.
|
||||
$ mc mb ~/
|
||||
|
||||
3. Create a bucket on Minio cloud storage.
|
||||
$ mc mb https://play.minio.io:9000/mongodb-backup
|
||||
```
|
||||
@@ -1,26 +0,0 @@
|
||||
#### mirror
|
||||
|
||||
```go
|
||||
NAME:
|
||||
mc mirror - Mirror files and folders from a single source to many destinations
|
||||
|
||||
USAGE:
|
||||
mc mirror SOURCE TARGET [TARGET...]
|
||||
|
||||
EXAMPLES:
|
||||
1. Mirror an object from local filesystem to Amazon S3 cloud storage.
|
||||
$ mc mirror star-trek-episode-10-season4.ogg https://s3.amazonaws.com/trekarchive
|
||||
|
||||
2. Mirror a bucket recursively from Minio cloud storage to multiple buckets on Amazon S3 cloud storage.
|
||||
$ mc mirror https://play.minio.io:9000/photos/2014... https://s3.amazonaws.com/backup-photos https://s3.amazonaws.com/my-photos
|
||||
|
||||
3. Mirror a local folder recursively to Minio cloud storage and Amazon S3 cloud storage.
|
||||
$ mc mirror backup/... https://play.minio.io:9000/archive https://s3.amazonaws.com/archive
|
||||
|
||||
4. Mirror a bucket from aliased Amazon S3 cloud storage to multiple folders on Windows.
|
||||
$ mc mirror s3:documents/2014/... C:\backup\2014 C:\shared\volume\backup\2014
|
||||
|
||||
5. Mirror a local file of non english character to Amazon s3 cloud storage.
|
||||
$ mc mirror 本語/... s3:mylocaldocuments C:\backup\2014 play:backup
|
||||
|
||||
```
|
||||
@@ -1,14 +0,0 @@
|
||||
#### update
|
||||
|
||||
```go
|
||||
Name:
|
||||
mc update - Check for new software updates
|
||||
|
||||
USAGE:
|
||||
mc update
|
||||
|
||||
EXAMPLES:
|
||||
1. Check for new updates
|
||||
$ mc update
|
||||
|
||||
```
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Minio Client (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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
// ContentMessage container for content message structure
|
||||
type ContentMessage struct {
|
||||
Filetype string `json:"type"`
|
||||
Time string `json:"last-modified"`
|
||||
Size string `json:"size"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// String string printer for Content metadata
|
||||
func (c ContentMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
message := console.Colorize("Time", fmt.Sprintf("[%s] ", c.Time))
|
||||
message = message + console.Colorize("Size", fmt.Sprintf("%6s ", c.Size))
|
||||
message = func() string {
|
||||
if c.Filetype == "folder" {
|
||||
return message + console.Colorize("Dir", fmt.Sprintf("%s", c.Name))
|
||||
}
|
||||
return message + console.Colorize("File", fmt.Sprintf("%s", c.Name))
|
||||
}()
|
||||
return message + "\n"
|
||||
}
|
||||
jsonMessageBytes, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(jsonMessageBytes) + "\n"
|
||||
}
|
||||
+3
-3
@@ -30,7 +30,7 @@ var lsCmd = cli.Command{
|
||||
mc {{.Name}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
mc {{.Name}} TARGET [TARGET...] {{if .Description}}
|
||||
mc {{.Name}} TARGET [TARGET ...] {{if .Description}}
|
||||
|
||||
DESCRIPTION:
|
||||
{{.Description}}{{end}}{{if .Flags}}
|
||||
@@ -83,10 +83,10 @@ func mainList(ctx *cli.Context) {
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range args {
|
||||
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
|
||||
fatalIf(err.Trace(), "Unable to canonicalize URL")
|
||||
fatalIf(err.Trace(arg), "Unable to parse argument ‘"+arg+"’.")
|
||||
|
||||
// if recursive strip off the "..."
|
||||
fatalIf(doListCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL)).Trace(), "Unable to list target URL")
|
||||
fatalIf(doListCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL)).Trace(), "Unable to list target ‘"+targetURL+"’.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
@@ -34,7 +35,35 @@ const (
|
||||
printDate = "2006-01-02 15:04:05 MST"
|
||||
)
|
||||
|
||||
// parseContent parse client Content container into printer struct
|
||||
// ContentMessage container for content message structure.
|
||||
type ContentMessage struct {
|
||||
Filetype string `json:"type"`
|
||||
Time string `json:"last-modified"`
|
||||
Size string `json:"size"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// String string printer for Content metadata.
|
||||
func (c ContentMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
message := console.Colorize("Time", fmt.Sprintf("[%s] ", c.Time))
|
||||
message = message + console.Colorize("Size", fmt.Sprintf("%6s ", c.Size))
|
||||
message = func() string {
|
||||
if c.Filetype == "folder" {
|
||||
return message + console.Colorize("Dir", fmt.Sprintf("%s", c.Name))
|
||||
}
|
||||
return message + console.Colorize("File", fmt.Sprintf("%s", c.Name))
|
||||
}()
|
||||
return message
|
||||
}
|
||||
jsonMessageBytes, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
// parseContent parse client Content container into printer struct.
|
||||
func parseContent(c *client.Content) ContentMessage {
|
||||
content := ContentMessage{}
|
||||
content.Time = c.Time.Local().Format(printDate)
|
||||
@@ -49,7 +78,7 @@ func parseContent(c *client.Content) ContentMessage {
|
||||
|
||||
content.Size = humanize.IBytes(uint64(c.Size))
|
||||
|
||||
// Convert OS Type to match console file printing style
|
||||
// Convert OS Type to match console file printing style.
|
||||
content.Name = func() string {
|
||||
switch {
|
||||
case runtime.GOOS == "windows":
|
||||
@@ -71,7 +100,7 @@ func parseContent(c *client.Content) ContentMessage {
|
||||
return content
|
||||
}
|
||||
|
||||
// doList - list all entities inside a folder
|
||||
// doList - list all entities inside a folder.
|
||||
func doList(clnt client.Client, recursive bool) *probe.Error {
|
||||
var err *probe.Error
|
||||
for contentCh := range clnt.List(recursive) {
|
||||
@@ -89,7 +118,7 @@ func doList(clnt client.Client, recursive bool) *probe.Error {
|
||||
err = contentCh.Err.Trace()
|
||||
break
|
||||
}
|
||||
console.Print(parseContent(contentCh.Content))
|
||||
console.Println(parseContent(contentCh.Content))
|
||||
}
|
||||
if err != nil {
|
||||
return err.Trace()
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -27,19 +28,18 @@ import (
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/probe"
|
||||
"github.com/minio/pb"
|
||||
)
|
||||
|
||||
// Check for the environment early on and gracefully report.
|
||||
func checkConfig() {
|
||||
_, err := user.Current()
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to determine current user. %s\n", err)
|
||||
}
|
||||
_, e := user.Current()
|
||||
fatalIf(probe.NewError(e), "Unable to determine current user.")
|
||||
|
||||
// Ensures config file is sane
|
||||
_, perr := getMcConfig()
|
||||
fatalIf(perr.Trace(), "Unable to read config")
|
||||
_, err := getMcConfig()
|
||||
fatalIf(err.Trace(), "Unable to access configuration file.")
|
||||
}
|
||||
|
||||
func migrate() {
|
||||
@@ -52,10 +52,9 @@ func migrate() {
|
||||
// Get os/arch/platform specific information.
|
||||
// Returns a map of current os/arch/platform/memstats
|
||||
func getSystemData() map[string]string {
|
||||
host, err := os.Hostname()
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to determine hostname. %s\n", err)
|
||||
}
|
||||
host, e := os.Hostname()
|
||||
fatalIf(probe.NewError(e), "Unable to determine the hostname.")
|
||||
|
||||
memstats := &runtime.MemStats{}
|
||||
runtime.ReadMemStats(memstats)
|
||||
mem := fmt.Sprintf("Used: %s | Allocated: %s | UsedHeap: %s | AllocatedHeap: %s",
|
||||
@@ -151,7 +150,7 @@ VERSION:
|
||||
{{end}}
|
||||
`
|
||||
app.CommandNotFound = func(ctx *cli.Context, command string) {
|
||||
console.Fatalf("Command not found: ‘%s’\n", command)
|
||||
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Command not found: ‘%s’", command))
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
+4
-6
@@ -31,7 +31,7 @@ var mbCmd = cli.Command{
|
||||
mc {{.Name}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
mc {{.Name}} TARGET [TARGET...] {{if .Description}}
|
||||
mc {{.Name}} TARGET [TARGET ...] {{if .Description}}
|
||||
|
||||
DESCRIPTION:
|
||||
{{.Description}}{{end}}{{if .Flags}}
|
||||
@@ -60,11 +60,9 @@ func mainMakeBucket(ctx *cli.Context) {
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range ctx.Args() {
|
||||
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
|
||||
fatalIf(err.Trace(), "Unable to canonicalize URL")
|
||||
|
||||
fatalIf(doMakeBucketCmd(targetURL).Trace(), "Unable to make bucket")
|
||||
|
||||
console.Infoln("Bucket created successfully : " + targetURL)
|
||||
fatalIf(err.Trace(arg), "Unable to parse argument ‘"+arg+"’.")
|
||||
fatalIf(doMakeBucketCmd(targetURL).Trace(targetURL), "Unable to make bucket ‘"+targetURL+"’.")
|
||||
console.Infoln("Bucket created successfully: " + targetURL)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Minio Client (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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// MirrorMessage container for file mirror messages
|
||||
type MirrorMessage struct {
|
||||
Source string `json:"source"`
|
||||
Targets []string `json:"targets"`
|
||||
Length int64 `json:"length"`
|
||||
}
|
||||
|
||||
// String string printer for mirror message
|
||||
func (s MirrorMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("‘%s’ -> ‘%s’\n", s.Source, s.Targets)
|
||||
}
|
||||
mirrorMessageBytes, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(mirrorMessageBytes) + "\n"
|
||||
}
|
||||
+1
-1
@@ -40,7 +40,7 @@ var mirrorCmd = cli.Command{
|
||||
mc {{.Name}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} SOURCE TARGET [TARGET...] {{if .Description}}
|
||||
mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} SOURCE TARGET [TARGET ...] {{if .Description}}
|
||||
|
||||
DESCRIPTION:
|
||||
{{.Description}}{{end}}{{if .Flags}}
|
||||
|
||||
+52
-29
@@ -17,13 +17,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/probe"
|
||||
"github.com/tchap/go-patricia/patricia"
|
||||
)
|
||||
@@ -44,6 +46,25 @@ func (m mirrorURLs) isEmpty() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// MirrorMessage container for file mirror messages
|
||||
type MirrorMessage struct {
|
||||
Source string `json:"source"`
|
||||
Targets []string `json:"targets"`
|
||||
Length int64 `json:"length"`
|
||||
}
|
||||
|
||||
// String string printer for mirror message
|
||||
func (s MirrorMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("‘%s’ -> ‘%s’", s.Source, s.Targets)
|
||||
}
|
||||
mirrorMessageBytes, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(mirrorMessageBytes)
|
||||
}
|
||||
|
||||
//
|
||||
// * MIRROR ARGS - VALID CASES
|
||||
// =========================
|
||||
@@ -57,7 +78,7 @@ func checkMirrorSyntax(ctx *cli.Context) {
|
||||
|
||||
// extract URLs.
|
||||
URLs, err := args2URLs(ctx.Args())
|
||||
fatalIf(err.Trace(), "Unable to convert args to URLs")
|
||||
fatalIf(err.Trace(ctx.Args()...), "Unable to parse arguments.")
|
||||
|
||||
srcURL := URLs[0]
|
||||
tgtURLs := URLs[1:]
|
||||
@@ -66,45 +87,47 @@ func checkMirrorSyntax(ctx *cli.Context) {
|
||||
// Source cannot be a folder (except when recursive)
|
||||
if !isURLRecursive(srcURL) {
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err.Trace(), "Unable to stat URL")
|
||||
fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+srcURL+"’.")
|
||||
|
||||
if !srcContent.Type.IsRegular() {
|
||||
if srcContent.Type.IsDir() {
|
||||
console.Fatalf("Source ‘%s’ is a folder. Please use ‘%s...’ to recursively copy this folder and its contents.\n", srcURL, srcURL)
|
||||
fatalIf(probe.NewError(errInvalidArgument), fmt.Sprintf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively.", srcURL, srcURL))
|
||||
}
|
||||
console.Fatalf("Source ‘%s’ is not a regular file.\n", srcURL)
|
||||
fatalIf(probe.NewError(errInvalidArgument), "Source ‘"+srcURL+"’ is not a file.")
|
||||
}
|
||||
}
|
||||
} else { // Recursive source URL.
|
||||
newSrcURL := stripRecursiveURL(srcURL)
|
||||
_, srcContent, err := url2Stat(newSrcURL)
|
||||
fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+newSrcURL+"’.")
|
||||
|
||||
for _, tgtURL := range tgtURLs {
|
||||
url, err := client.Parse(tgtURL)
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to parse target ‘%s’ argument. %s\n", tgtURL, err)
|
||||
}
|
||||
if url.Host != "" {
|
||||
if url.Path == string(url.Separator) {
|
||||
console.Fatalf("Bucket creation detected for %s, cloud storage URL's should use ‘mc mb’ to create buckets\n", tgtURL)
|
||||
}
|
||||
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
|
||||
fatalIf(probe.NewError(errInvalidArgument), "Source ‘"+srcURL+"’ is not a folder.")
|
||||
}
|
||||
}
|
||||
|
||||
if len(tgtURLs) == 0 && tgtURLs == nil {
|
||||
console.Fatalf("Invalid number of target arguments to mirror command. %s\n", errInvalidArgument)
|
||||
fatalIf(probe.NewError(errInvalidArgument), "Invalid number of target arguments to mirror command.")
|
||||
}
|
||||
|
||||
_, srcContent, err := url2Stat(stripRecursiveURL(srcURL))
|
||||
fatalIf(err.Trace(), "Unable to stat source URL.")
|
||||
|
||||
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
|
||||
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}), "Invalid target type.")
|
||||
// Recursive URLs are not allowed in target.
|
||||
if isURLRecursive(tgtURL) {
|
||||
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Recursive option is not supported for target ‘%s’ argument.", tgtURL))
|
||||
}
|
||||
|
||||
url, e := client.Parse(tgtURL)
|
||||
fatalIf(probe.NewError(e), "Unable to parse target ‘"+tgtURL+"’ argument.")
|
||||
|
||||
if url.Host != "" {
|
||||
if url.Path == string(url.Separator) {
|
||||
fatalIf(probe.NewError(errInvalidArgument), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL))
|
||||
}
|
||||
}
|
||||
_, content, err := url2Stat(tgtURL)
|
||||
fatalIf(err.Trace(tgtURL), "Unable to stat target ‘"+tgtURL+"’.")
|
||||
if !content.Type.IsDir() {
|
||||
fatalIf(probe.NewError(errInvalidArgument), "Target ‘"+tgtURL+"’ is not a folder.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +212,7 @@ func prepareMirrorURLs(sourceURL string, targetURLs []string) <-chan mirrorURLs
|
||||
defer close(mirrorURLsCh)
|
||||
sourceClnt, err := url2Client(stripRecursiveURL(sourceURL))
|
||||
if err != nil {
|
||||
mirrorURLsCh <- mirrorURLs{Error: err.Trace()}
|
||||
mirrorURLsCh <- mirrorURLs{Error: err.Trace(sourceURL)}
|
||||
return
|
||||
}
|
||||
targetClnts := make([]client.Client, len(targetURLs))
|
||||
@@ -197,7 +220,7 @@ func prepareMirrorURLs(sourceURL string, targetURLs []string) <-chan mirrorURLs
|
||||
targetURL = stripRecursiveURL(targetURL)
|
||||
targetClnt, targetContent, err := url2Stat(targetURL)
|
||||
if err != nil {
|
||||
mirrorURLsCh <- mirrorURLs{Error: err.Trace()}
|
||||
mirrorURLsCh <- mirrorURLs{Error: err.Trace(targetURL)}
|
||||
return
|
||||
}
|
||||
// if one of the targets is not dir exit
|
||||
@@ -209,7 +232,7 @@ func prepareMirrorURLs(sourceURL string, targetURLs []string) <-chan mirrorURLs
|
||||
newTargetURL := strings.TrimSuffix(targetURL, string(targetClnt.URL().Separator)) + string(targetClnt.URL().Separator)
|
||||
targetClnt, err = url2Client(newTargetURL)
|
||||
if err != nil {
|
||||
mirrorURLsCh <- mirrorURLs{Error: err.Trace()}
|
||||
mirrorURLsCh <- mirrorURLs{Error: err.Trace(newTargetURL)}
|
||||
return
|
||||
}
|
||||
targetClnts[i] = targetClnt
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Minio Client (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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
// SessionJSONMessage json container for session messages
|
||||
type SessionJSONMessage struct {
|
||||
SessionID string `json:"sessionid"`
|
||||
Time string `json:"time"`
|
||||
CommandType string `json:"command-type"`
|
||||
CommandArgs []string `json:"command-args"`
|
||||
}
|
||||
|
||||
func (s sessionV2) String() string {
|
||||
if !globalJSONFlag {
|
||||
message := console.Colorize("SessionID", fmt.Sprintf("%s -> ", s.SessionID))
|
||||
message = message + console.Colorize("Time", fmt.Sprintf("[%s]", s.Header.When.Local().Format(printDate)))
|
||||
message = message + console.Colorize("Command", fmt.Sprintf(" %s %s", s.Header.CommandType, strings.Join(s.Header.CommandArgs, " ")))
|
||||
return message + "\n"
|
||||
}
|
||||
sessionMesage := SessionJSONMessage{
|
||||
SessionID: s.SessionID,
|
||||
Time: s.Header.When.Local().Format(printDate),
|
||||
CommandType: s.Header.CommandType,
|
||||
CommandArgs: s.Header.CommandArgs,
|
||||
}
|
||||
sessionJSONBytes, err := json.Marshal(sessionMesage)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(sessionJSONBytes) + "\n"
|
||||
}
|
||||
@@ -19,9 +19,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -54,6 +57,14 @@ type sessionV2Header struct {
|
||||
TotalObjects int `json:"total-objects"`
|
||||
}
|
||||
|
||||
// SessionJSONMessage json container for session messages
|
||||
type SessionJSONMessage struct {
|
||||
SessionID string `json:"sessionid"`
|
||||
Time string `json:"time"`
|
||||
CommandType string `json:"command-type"`
|
||||
CommandArgs []string `json:"command-args"`
|
||||
}
|
||||
|
||||
// sessionV2
|
||||
type sessionV2 struct {
|
||||
Header *sessionV2Header
|
||||
@@ -63,6 +74,26 @@ type sessionV2 struct {
|
||||
sigCh bool
|
||||
}
|
||||
|
||||
func (s sessionV2) String() string {
|
||||
if !globalJSONFlag {
|
||||
message := console.Colorize("SessionID", fmt.Sprintf("%s -> ", s.SessionID))
|
||||
message = message + console.Colorize("Time", fmt.Sprintf("[%s]", s.Header.When.Local().Format(printDate)))
|
||||
message = message + console.Colorize("Command", fmt.Sprintf(" %s %s", s.Header.CommandType, strings.Join(s.Header.CommandArgs, " ")))
|
||||
return message + "\n"
|
||||
}
|
||||
sessionMesage := SessionJSONMessage{
|
||||
SessionID: s.SessionID,
|
||||
Time: s.Header.When.Local().Format(printDate),
|
||||
CommandType: s.Header.CommandType,
|
||||
CommandArgs: s.Header.CommandArgs,
|
||||
}
|
||||
sessionJSONBytes, err := json.Marshal(sessionMesage)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(sessionJSONBytes) + "\n"
|
||||
}
|
||||
|
||||
// newSessionV2 provides a new session
|
||||
func newSessionV2() *sessionV2 {
|
||||
s := &sessionV2{}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Minio Client (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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ShareMessage container for share messages
|
||||
type ShareMessage struct {
|
||||
Expires time.Duration `json:"expire-seconds"`
|
||||
PresignedURL string `json:"presigned-url"`
|
||||
}
|
||||
|
||||
// String string printer for share message
|
||||
func (s ShareMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("Succesfully generated shared URL with expiry %s, please share: %s\n", s.Expires, s.PresignedURL)
|
||||
}
|
||||
shareMessageBytes, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// json encoding escapes ampersand into its unicode character which is not usable directly for share
|
||||
// and fails with cloud storage. convert them back so that they are usable
|
||||
shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u0026"), []byte("&"), -1)
|
||||
return fmt.Sprintf("%s\n", string(shareMessageBytes))
|
||||
}
|
||||
+25
-1
@@ -17,7 +17,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -76,12 +79,33 @@ func mainShare(ctx *cli.Context) {
|
||||
fatalIf(probe.NewError(err), "Unable to parse time argument")
|
||||
}
|
||||
targetURL, err := getCanonicalizedURL(url, config.Aliases)
|
||||
fatalIf(err.Trace(), "Unable to canonicalize URL")
|
||||
fatalIf(err.Trace(url), "Unable to parse argument ‘"+url+"’.")
|
||||
|
||||
// if recursive strip off the "..."
|
||||
fatalIf(doShareCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL), expires).Trace(), "Unable generate URL for sharing")
|
||||
}
|
||||
|
||||
// ShareMessage container for share messages
|
||||
type ShareMessage struct {
|
||||
Expires time.Duration `json:"expire-seconds"`
|
||||
PresignedURL string `json:"presigned-url"`
|
||||
}
|
||||
|
||||
// String string printer for share message
|
||||
func (s ShareMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("Succesfully generated shared URL with expiry %s, please share: %s\n", s.Expires, s.PresignedURL)
|
||||
}
|
||||
shareMessageBytes, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// json encoding escapes ampersand into its unicode character which is not usable directly for share
|
||||
// and fails with cloud storage. convert them back so that they are usable
|
||||
shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u0026"), []byte("&"), -1)
|
||||
return fmt.Sprintf("%s\n", string(shareMessageBytes))
|
||||
}
|
||||
|
||||
func getNewTargetURL(targetParser *client.URL, name string) string {
|
||||
match, _ := filepath.Match("*.s3*.amazonaws.com", targetParser.Host)
|
||||
if match {
|
||||
|
||||
@@ -73,12 +73,6 @@ func (e errInvalidTarget) Error() string {
|
||||
return "Invalid target " + e.URL
|
||||
}
|
||||
|
||||
type errTargetIsNotDir errInvalidURL
|
||||
|
||||
func (e errTargetIsNotDir) Error() string {
|
||||
return "Target ‘" + e.URL + "’ is not a folder."
|
||||
}
|
||||
|
||||
type errSourceNotRecursive errInvalidURL
|
||||
|
||||
func (e errSourceNotRecursive) Error() string {
|
||||
|
||||
Reference in New Issue
Block a user