Now fs behaves similar to s3 style delimited output

This commit is contained in:
Harshavardhana
2015-06-06 21:23:33 -07:00
parent dd7673e4dd
commit e95c3bd3e8
4 changed files with 14 additions and 30 deletions
+6 -12
View File
@@ -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)
}
+1 -6
View File
@@ -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 {
+4 -4
View File
@@ -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)
}
+3 -8
View File
@@ -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(),