Merge pull request #681 from harshavardhana/pr_out_add_recursive_listing_with_s3_
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
+45
-14
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user