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

Add ListOnChannel() for fs{unix,windows} and cmd-ls

This commit is contained in:
Harshavardhana
2015-04-23 20:02:48 -07:00
parent 1f0d1547c7
commit 972c476e36
5 changed files with 74 additions and 52 deletions

View File

@@ -22,7 +22,6 @@ import (
"io"
"os"
"path/filepath"
"sort"
"strings"
"io/ioutil"
@@ -118,9 +117,31 @@ func (f *fsClient) ListOnChannel() <-chan client.ItemOnChannel {
func (f *fsClient) listInGoroutine(itemCh chan client.ItemOnChannel) {
defer close(itemCh)
itemCh <- client.ItemOnChannel{
Item: nil,
Err: iodine.New(client.APINotImplemented{API: "ListOnChannel"}, nil),
visitFS := func(fp string, fi os.FileInfo, err error) error {
if err != nil {
if os.IsPermission(err) { // skip inaccessible files
return nil
}
return err // fatal
}
item := &client.Item{
Name: fp,
Time: fi.ModTime(),
Size: fi.Size(),
FileType: fi.Mode(),
}
itemCh <- client.ItemOnChannel{
Item: item,
Err: nil,
}
return nil
}
err := filepath.Walk(f.path, visitFS)
if err != nil {
itemCh <- client.ItemOnChannel{
Item: nil,
Err: iodine.New(err, nil),
}
}
}
@@ -146,7 +167,6 @@ func (f *fsClient) List() (items []*client.Item, err error) {
if err != nil {
return nil, iodine.New(err, nil)
}
sort.Sort(client.BySize(items))
return items, nil
}