From bb065502dde22cad9d5b17d5c636a82007bafd2d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 27 Apr 2015 21:12:09 -0700 Subject: [PATCH] Update ls docs and fix a bug --- cmd-options.go | 37 +++++++++++++++++++++---------------- pkg/client/fs/fs.go | 35 ++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/cmd-options.go b/cmd-options.go index f9d56c1b..94859988 100644 --- a/cmd-options.go +++ b/cmd-options.go @@ -135,27 +135,32 @@ FLAGS: {{end}}{{ end }} EXAMPLES: - 1. List objects on Minio object storage - $ mc {{.Name}} http://localhost:9000/backup/ - 2015-03-28 12:47:50 PDT 51.00 MB 2006-Jan-1/backup.tar.gz - 2015-03-31 14:46:33 PDT 55.00 MB 2006-Mar-1/backup.tar.gz + 1. List objects recursively on Minio object storage + $ mc {{.Name}} http://localhost: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 object storage $ mc {{.Name}} https://s3.amazonaws.com/ - 2015-01-20 15:42:00 PST rom - 2015-01-15 00:05:40 PST zek + [2015-01-20 15:42:00 PST] 0B rom/ + [2015-01-15 00:05:40 PST] 0B zek/ - 3. List buckets and objects from Minio object storage and Amazon S3 object storage - $ mc {{.Name}} https://s3.amazonaws.com/ http://localhost:9000/backup/ - 2015-01-20 15:42:00 PST rom - 2015-01-15 00:05:40 PST zek - 2015-03-28 12:47:50 PDT 51.00 MB 2006-Jan-1/backup.tar.gz - 2015-03-31 14:46:33 PDT 55.00 MB 2006-Mar-1/backup.tar.gz + 3. List buckets from Amazon S3 object storage and recursively list objects from Minio object storage + $ mc {{.Name}} https://s3.amazonaws.com/ http://localhost: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 objects on local filesystem on Windows - $ mc {{.Name}} C:\Users\Worf - 2015-03-28 12:47:50 PDT 11.00 MB Martok\Klingon Council Ministers.pdf - 2015-03-31 14:46:33 PDT 15.00 MB Gowron\Khitomer Conference Details.pdf + 4. List files recursively on local filesystem on Windows + $ mc {{.Name}} 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 non recursively on local filesystem + $ mc {{.Name}} /usr/lib/llvm-3.4 + [2015-04-01 14:57:17 PDT] 12KiB lib/ + [2015-04-01 14:57:17 PDT] 4.0KiB include/ + [2015-04-01 14:57:10 PDT] 4.0KiB build/ + [2015-04-01 14:57:07 PDT] 4.0KiB bin/ `, } diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index cdc99668..1317f9c6 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -138,20 +138,41 @@ func (f *fsClient) listSingle(itemCh chan client.ItemOnChannel) { Err: iodine.New(err, nil), } } - files, err := dir.Readdir(-1) + fi, err := dir.Stat() if err != nil { itemCh <- client.ItemOnChannel{ Item: nil, Err: iodine.New(err, nil), } } - dir.Close() - for _, file := range files { + defer dir.Close() + if fi.Mode().IsDir() { + files, err := dir.Readdir(-1) + if err != nil { + itemCh <- client.ItemOnChannel{ + Item: nil, + Err: iodine.New(err, nil), + } + } + for _, file := range files { + item := &client.Item{ + Name: file.Name(), + Time: file.ModTime(), + Size: file.Size(), + FileType: file.Mode(), + } + itemCh <- client.ItemOnChannel{ + Item: item, + Err: nil, + } + } + } + if fi.Mode().IsRegular() { item := &client.Item{ - Name: file.Name(), - Time: file.ModTime(), - Size: file.Size(), - FileType: file.Mode(), + Name: dir.Name(), + Time: fi.ModTime(), + Size: fi.Size(), + FileType: fi.Mode(), } itemCh <- client.ItemOnChannel{ Item: item,