Skip to content

Commit

Permalink
memfs: fix Stat for directories
Browse files Browse the repository at this point in the history
* memfs: fix Stat for directories: isDir now returns true for them.

* memfs: fix FileInfo Size for directories.

* test: added further tests for Stat on directories
  • Loading branch information
smola committed Feb 16, 2017
1 parent f84fa56 commit 9e3fab6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion memfs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func (fs *Memory) Stat(filename string) (billy.FileInfo, error) {

info, err := fs.ReadDir(fullpath)
if err == nil && len(info) != 0 {
return newFileInfo(fs.base, fullpath, len(info)+100), nil
fi := newFileInfo(fs.base, fullpath, len(info))
fi.isDir = true
return fi, nil
}

return nil, os.ErrNotExist
Expand Down
10 changes: 9 additions & 1 deletion test/fs_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,22 @@ func (s *FilesystemSuite) TestDirStat(c *C) {
c.Assert(f.Close(), IsNil)
}

fi, err := s.Fs.Stat("qux")
c.Assert(err, IsNil)
c.Assert(fi.Name(), Equals, "qux")
c.Assert(fi.IsDir(), Equals, true)

qux := s.Fs.Dir("qux")
fi, err := qux.Stat("baz")

fi, err = qux.Stat("baz")
c.Assert(err, IsNil)
c.Assert(fi.Name(), Equals, "baz")
c.Assert(fi.IsDir(), Equals, false)

fi, err = qux.Stat("/baz")
c.Assert(err, IsNil)
c.Assert(fi.Name(), Equals, "baz")
c.Assert(fi.IsDir(), Equals, false)
}

func (s *FilesystemSuite) TestCreateInDir(c *C) {
Expand Down

0 comments on commit 9e3fab6

Please sign in to comment.