Skip to content

Commit 97730a4

Browse files
committed
memory: fix Stats size
1 parent f7d4d71 commit 97730a4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

memory/memory.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ func (fs *Memory) OpenFile(filename string, flag int, perm os.FileMode) (billy.F
7272
func (fs *Memory) Stat(filename string) (billy.FileInfo, error) {
7373
fullpath := fs.Join(fs.base, filename)
7474

75-
if _, ok := fs.s.files[filename]; ok {
76-
return newFileInfo(fs.base, fullpath, fs.s.files[filename].content.Len()), nil
75+
if _, ok := fs.s.files[fullpath]; ok {
76+
return newFileInfo(fs.base, fullpath, fs.s.files[fullpath].content.Len()), nil
7777
}
7878

79-
info, err := fs.ReadDir(filename)
79+
info, err := fs.ReadDir(fullpath)
8080
if err == nil && len(info) != 0 {
81-
return newFileInfo(fs.base, fullpath, len(info)), nil
81+
return newFileInfo(fs.base, fullpath, len(info)+100), nil
8282
}
8383

8484
return nil, os.ErrNotExist

test/fs_suite.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package test
22

33
import (
4+
"bytes"
45
"fmt"
56
"io"
67
"io/ioutil"
78
"os"
89
"strings"
910
"testing"
1011

11-
"bytes"
12-
1312
. "gopkg.in/check.v1"
1413
. "srcd.works/go-billy.v1"
1514
)
@@ -379,6 +378,8 @@ func (s *FilesystemSuite) TestOpenAndWrite(c *C) {
379378
func (s *FilesystemSuite) TestOpenAndStat(c *C) {
380379
f, err := s.Fs.Create("foo")
381380
c.Assert(err, IsNil)
381+
_, err = f.Write([]byte("foo"))
382+
c.Assert(err, IsNil)
382383
c.Assert(f.Close(), IsNil)
383384

384385
foo, err := s.Fs.Open("foo")
@@ -390,6 +391,7 @@ func (s *FilesystemSuite) TestOpenAndStat(c *C) {
390391
c.Assert(stat, NotNil)
391392
c.Assert(err, IsNil)
392393
c.Assert(stat.Name(), Equals, "foo")
394+
c.Assert(stat.Size(), Equals, int64(3))
393395
}
394396

395397
func (s *FilesystemSuite) TestRemove(c *C) {

0 commit comments

Comments
 (0)