From 33f4c653490156959d2125d6daa9e1e63db4bad1 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 6 Jun 2015 12:29:12 -0700 Subject: [PATCH] Delimit fs output similar to s3, no special handling needed --- ls.go | 12 ------------ pkg/client/fs/fs.go | 13 ++++++++++++- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ls.go b/ls.go index 8fe042d6..9c199b88 100644 --- a/ls.go +++ b/ls.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "path/filepath" "runtime" "strings" @@ -75,17 +74,6 @@ func doList(clnt client.Client, targetURL string, recursive bool, recursivePrefi err = contentCh.Err break } - contentName := contentCh.Content.Name - if recursive { - // this special handling is necessary since we are sending back absolute paths with in ListRecursive() - // a user would not wish to see a URL just for recursive and not for regular List() - // - // To be consistent we have to filter them out - contentName = strings.TrimPrefix(contentName, - strings.TrimSuffix(targetURL, string(filepath.Separator))+string(filepath.Separator)) - contentName = filepath.Join(recursivePrefix, contentName) - } - contentCh.Content.Name = contentName console.Println(parseContent(contentCh.Content)) } if err != nil { diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index effc7fc8..119af2b9 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -260,6 +260,17 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { } } +func (f *fsClient) delimiter(fp string) string { + var stripPrefix string + if strings.LastIndex(f.path, string(filepath.Separator)) == 0 { + stripPrefix = string(filepath.Separator) + } + if strings.LastIndex(f.path, string(filepath.Separator)) > 0 { + stripPrefix = f.path + } + return strings.TrimPrefix(fp, stripPrefix) +} + func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel) { defer close(contentCh) visitFS := func(fp string, fi os.FileInfo, err error) error { @@ -287,7 +298,7 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel } if fi.Mode().IsRegular() || fi.Mode().IsDir() { content := &client.Content{ - Name: strings.TrimPrefix(fp, f.path), + Name: f.delimiter(fp), Time: fi.ModTime(), Size: fi.Size(), Type: fi.Mode(),