diff --git a/cmd-ls.go b/cmd-ls.go index 9715287d..3aa367b7 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -19,8 +19,6 @@ package main import ( "errors" "fmt" - "path/filepath" - "strings" "github.com/minio/cli" "github.com/minio/mc/pkg/console" @@ -119,8 +117,9 @@ func runListCmd(ctx *cli.Context) { targetConfig, err := getHostConfig(targetURL) if err != nil { console.Fatals(ErrorMessage{ - Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", targetURL, mustGetMcConfigPath()), - Error: iodine.New(err, nil), + Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", + targetURL, mustGetMcConfigPath()), + Error: iodine.New(err, nil), }) } targetURLConfigMap[targetURL] = targetConfig @@ -128,12 +127,7 @@ func runListCmd(ctx *cli.Context) { for targetURL, targetConfig := range targetURLConfigMap { // if recursive strip off the "..." newTargetURL := stripRecursiveURL(targetURL) - // is set when ... includes a directory, i.e. /path/to/dir... instead of path/to/dir/... - recursivePrefix := "" - if isURLRecursive(targetURL) && !strings.HasSuffix(newTargetURL, string(filepath.Separator)) { - recursivePrefix = filepath.Base(newTargetURL) - } - err = doListCmd(newTargetURL, targetConfig, isURLRecursive(targetURL), recursivePrefix) + err = doListCmd(newTargetURL, targetConfig, isURLRecursive(targetURL)) if err != nil { console.Fatals(ErrorMessage{ Message: fmt.Sprintf("Failed to list ‘%s’", targetURL), @@ -144,12 +138,12 @@ func runListCmd(ctx *cli.Context) { } // doListCmd - -func doListCmd(targetURL string, targetConfig *hostConfig, recursive bool, recursivePrefix string) error { +func doListCmd(targetURL string, targetConfig *hostConfig, recursive bool) error { clnt, err := getNewClient(targetURL, targetConfig) if err != nil { return iodine.New(err, map[string]string{"Target": targetURL}) } - err = doList(clnt, targetURL, recursive, recursivePrefix) + err = doList(clnt, targetURL, recursive) if err != nil { return iodine.New(err, nil) } diff --git a/ls.go b/ls.go index af6beff2..e1eeebc8 100644 --- a/ls.go +++ b/ls.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "path/filepath" "runtime" "strings" @@ -68,17 +67,13 @@ func parseContent(c *client.Content) Content { } // doList - list all entities inside a folder -func doList(clnt client.Client, targetURL string, recursive bool, recursivePrefix string) error { +func doList(clnt client.Client, targetURL string, recursive bool) error { var err error for contentCh := range clnt.List(recursive) { if contentCh.Err != nil { err = contentCh.Err break } - - if recursive && recursivePrefix != "" { - contentCh.Content.Name = filepath.Join(filepath.Base(targetURL), contentCh.Content.Name) - } console.Println(parseContent(contentCh.Content)) } if err != nil { diff --git a/ls_test.go b/ls_test.go index d549f0ed..1249ad0b 100644 --- a/ls_test.go +++ b/ls_test.go @@ -40,10 +40,10 @@ func (s *CmdTestSuite) TestLSCmd(c *C) { c.Assert(err, IsNil) } - err = doListCmd(root, &hostConfig{}, false, "") + err = doListCmd(root, &hostConfig{}, false) c.Assert(err, IsNil) - err = doListCmd(root, &hostConfig{}, true, "test") + err = doListCmd(root, &hostConfig{}, true) c.Assert(err, IsNil) for i := 0; i < 10; i++ { @@ -53,10 +53,10 @@ func (s *CmdTestSuite) TestLSCmd(c *C) { err := putTarget(objectPath, &hostConfig{}, int64(dataLen), bytes.NewReader([]byte(data))) c.Assert(err, IsNil) } - err = doListCmd(server.URL+"/bucket", &hostConfig{}, false, "") + err = doListCmd(server.URL+"/bucket", &hostConfig{}, false) c.Assert(err, IsNil) - err = doListCmd(server.URL+"/bucket", &hostConfig{}, true, "test") + err = doListCmd(server.URL+"/bucket", &hostConfig{}, true) c.Assert(err, IsNil) } diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index 119af2b9..98fd1c3c 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -260,14 +260,9 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { } } -func (f *fsClient) delimiter(fp string) string { +func (f *fsClient) delimited(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 - } + stripPrefix = f.path[:strings.LastIndex(f.path, string(filepath.Separator))+1] return strings.TrimPrefix(fp, stripPrefix) } @@ -298,7 +293,7 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel } if fi.Mode().IsRegular() || fi.Mode().IsDir() { content := &client.Content{ - Name: f.delimiter(fp), + Name: f.delimited(fp), Time: fi.ModTime(), Size: fi.Size(), Type: fi.Mode(),