diff --git a/cmd-ls.go b/cmd-ls.go index 7d59a430..ecceff6c 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -30,14 +30,12 @@ func runListCmd(ctx *cli.Context) { if !ctx.Args().Present() || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code } - if !isMcConfigExist() { console.Fatalln(console.ErrorMessage{ Message: "Please run \"mc config generate\"", Error: iodine.New(errors.New("\"mc\" is not configured"), nil), }) } - config, err := getMcConfig() if err != nil { console.Fatalln(console.ErrorMessage{ diff --git a/ls.go b/ls.go index eb275e2c..5be353d0 100644 --- a/ls.go +++ b/ls.go @@ -46,11 +46,13 @@ func printContent(c *client.Content) { return "application/octet-stream" }() content.Size = humanize.IBytes(uint64(c.Size)) - if runtime.GOOS == "windows" { + switch { + case runtime.GOOS == "windows": content.Name = strings.Replace(c.Name, "/", "\\", -1) content.Name = strings.TrimSuffix(content.Name, "\\") + default: + content.Name = strings.TrimSuffix(c.Name, "/") } - content.Name = strings.TrimSuffix(content.Name, "/") content.Time = c.Time.Local().Format(printDate) console.ContentInfo(content) } diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index 24879ca4..9b222da2 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -267,22 +267,53 @@ func (c *s3Client) listInRoutine(contentCh chan client.ContentOnChannel) { func (c *s3Client) listRecursiveInRoutine(contentCh chan client.ContentOnChannel) { defer close(contentCh) bucket, object := c.url2BucketAndObject() - for object := range c.api.ListObjects(bucket, object, true) { - if object.Err != nil { - contentCh <- client.ContentOnChannel{ - Content: nil, - Err: object.Err, + switch { + case bucket == "" && object == "": + for bucket := range c.api.ListBuckets() { + if bucket.Err != nil { + contentCh <- client.ContentOnChannel{ + Content: nil, + Err: bucket.Err, + } + return + } + for object := range c.api.ListObjects(bucket.Data.Name, object, true) { + if object.Err != nil { + contentCh <- client.ContentOnChannel{ + Content: nil, + Err: object.Err, + } + return + } + content := new(client.Content) + content.Name = strings.TrimSuffix(c.hostURL.String(), "/") + "/" + object.Data.Key + content.Size = object.Data.Size + content.Time = object.Data.LastModified + content.Type = os.FileMode(0664) + contentCh <- client.ContentOnChannel{ + Content: content, + Err: nil, + } } - return } - content := new(client.Content) - content.Name = strings.TrimSuffix(c.hostURL.String(), "/") + "/" + object.Data.Key - content.Size = object.Data.Size - content.Time = object.Data.LastModified - content.Type = os.FileMode(0664) - contentCh <- client.ContentOnChannel{ - Content: content, - Err: nil, + default: + for object := range c.api.ListObjects(bucket, object, true) { + if object.Err != nil { + contentCh <- client.ContentOnChannel{ + Content: nil, + Err: object.Err, + } + return + } + content := new(client.Content) + content.Name = strings.TrimSuffix(c.hostURL.String(), "/") + "/" + object.Data.Key + content.Size = object.Data.Size + content.Time = object.Data.LastModified + content.Type = os.FileMode(0664) + contentCh <- client.ContentOnChannel{ + Content: content, + Err: nil, + } } } }