fs: Make fs behave like s3 for prefix directories

This commit is contained in:
Harshavardhana
2015-11-15 13:17:17 -08:00
parent 68d6066778
commit 540b72426a
2 changed files with 19 additions and 19 deletions
+15 -5
View File
@@ -241,11 +241,6 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
pathURL := *f.PathURL
fpath := pathURL.Path
// Golang strips trailing / if you clean(..) or
// EvalSymlinks(..). Adding '.' prevents it from doing so.
if strings.HasSuffix(fpath, string(pathURL.Separator)) {
fpath = fpath + "."
}
fst, err := f.fsStat()
if err != nil {
@@ -312,6 +307,21 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
return
}
// if the directory doesn't end with a separator, do not traverse it.
if !strings.HasSuffix(fpath, string(pathURL.Separator)) && fst.Mode().IsDir() {
content := &client.Content{
URL: pathURL,
Time: fst.ModTime(),
Size: fst.Size(),
Type: fst.Mode(),
}
contentCh <- client.ContentOnChannel{
Content: content,
Err: nil,
}
return
}
switch fst.Mode().IsDir() {
case true:
// do not use ioutil.ReadDir(), since it tries to sort its
+4 -14
View File
@@ -69,11 +69,8 @@ func (s *MySuite) TestList(c *C) {
contents = append(contents, contentCh.Content)
}
c.Assert(perr, IsNil)
c.Assert(len(contents), Equals, 2)
for _, content := range contents {
c.Assert(content.Type.IsRegular(), Equals, true)
}
c.Assert(len(contents), Equals, 1)
c.Assert(contents[0].Type.IsDir(), Equals, true)
objectPath = filepath.Join(root, "test1/newObject1")
fsc, perr = fs.New(objectPath)
@@ -94,15 +91,8 @@ func (s *MySuite) TestList(c *C) {
contents = append(contents, contentCh.Content)
}
c.Assert(perr, IsNil)
c.Assert(len(contents), Equals, 3)
for _, content := range contents {
// skip previous regular files
if content.Type.IsRegular() {
continue
}
c.Assert(content.Type.IsDir(), Equals, true)
}
c.Assert(len(contents), Equals, 1)
c.Assert(contents[0].Type.IsDir(), Equals, true)
fsc, perr = fs.New(root)
c.Assert(err, IsNil)