From 5ca4280ea0e7a526ddd6ad62728592fa6f0d4a37 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 28 Apr 2015 23:26:17 -0700 Subject: [PATCH] Handle symlink appropriately with mc ls for filesystem --- ls.go | 6 +++--- pkg/client/fs/fs.go | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ls.go b/ls.go index 4bbbeddf..611b8526 100644 --- a/ls.go +++ b/ls.go @@ -41,15 +41,15 @@ func printItem(date time.Time, v int64, name string, fileType os.FileMode) { fmt.Printf(console.Size("%6s ", humanize.IBytes(uint64(v)))) // just making it explicit - if fileType.IsDir() { + switch fileType.IsDir() { + case true: // if one finds a prior suffix no need to append a new one if strings.HasSuffix(name, "/") { fmt.Println(console.Dir("%s", name)) } else { fmt.Println(console.Dir("%s/", name)) } - } - if fileType.IsRegular() { + default: fmt.Println(console.File("%s", name)) } } diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index 020b1e0d..f5cf13e1 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -47,7 +47,7 @@ func New(path string) client.Client { // fsStat - wrapper function to get file stat func (f *fsClient) fsStat() (os.FileInfo, error) { - st, err := os.Stat(filepath.Clean(f.path)) + st, err := os.Lstat(filepath.Clean(f.path)) if os.IsNotExist(err) { return nil, iodine.New(NotFound{path: f.path}, nil) } @@ -139,7 +139,7 @@ func (f *fsClient) list(itemCh chan client.ItemOnChannel) { Err: iodine.New(err, nil), } } - fi, err := dir.Stat() + fi, err := os.Lstat(f.path) if err != nil { itemCh <- client.ItemOnChannel{ Item: nil, @@ -147,7 +147,8 @@ func (f *fsClient) list(itemCh chan client.ItemOnChannel) { } } defer dir.Close() - if fi.Mode().IsDir() { + switch fi.Mode().IsDir() { + case true: // do not use ioutil.ReadDir(), since it tries to sort its // output at our scale we are expecting that to slow down // instead we take raw output and provide it back to the user @@ -172,8 +173,7 @@ func (f *fsClient) list(itemCh chan client.ItemOnChannel) { Err: nil, } } - } - if fi.Mode().IsRegular() { + default: item := &client.Item{ Name: dir.Name(), Time: fi.ModTime(),