From 32c610c0000b7af5c85e69306853636a77f2168b Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sun, 20 Nov 2016 12:25:10 +0100 Subject: utils: fs, memory fix read offset --- utils/fs/memory/memory.go | 2 +- utils/fs/test/fs_suite.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'utils') diff --git a/utils/fs/memory/memory.go b/utils/fs/memory/memory.go index 398ac35..54dd497 100644 --- a/utils/fs/memory/memory.go +++ b/utils/fs/memory/memory.go @@ -40,6 +40,7 @@ func (fs *Memory) Open(filename string) (fs.File, error) { func (fs *Memory) OpenFile(filename string, flag int, perm os.FileMode) (fs.File, error) { fullpath := fs.Join(fs.base, filename) f, ok := fs.s.files[fullpath] + if !ok && !isCreate(flag) { return nil, os.ErrNotExist } @@ -194,7 +195,6 @@ func (f *file) Read(b []byte) (int, error) { return 0, err } - f.position += int64(n) return n, err } diff --git a/utils/fs/test/fs_suite.go b/utils/fs/test/fs_suite.go index 01d6112..91b2be5 100644 --- a/utils/fs/test/fs_suite.go +++ b/utils/fs/test/fs_suite.go @@ -8,6 +8,8 @@ import ( "strings" "testing" + "bytes" + . "gopkg.in/check.v1" . "gopkg.in/src-d/go-git.v4/utils/fs" ) @@ -455,3 +457,23 @@ func (s *FilesystemSuite) TestReadAtOnReadOnly(c *C) { c.Assert(string(b), Equals, "cde") c.Assert(f.Close(), IsNil) } + +func (s *FilesystemSuite) TestReadWriteLargeFile(c *C) { + f, err := s.Fs.Create("foo") + c.Assert(err, IsNil) + + size := 1 << 20 + + n, err := f.Write(bytes.Repeat([]byte("F"), size)) + c.Assert(err, IsNil) + c.Assert(n, Equals, size) + + err = f.Close() + c.Assert(err, IsNil) + + f, err = s.Fs.Open("foo") + c.Assert(err, IsNil) + b, err := ioutil.ReadAll(f) + c.Assert(err, IsNil) + c.Assert(len(b), Equals, size) +} -- cgit