From 130b35a825c6490ae11b2f88dd80cb8ac6a90794 Mon Sep 17 00:00:00 2001 From: uz Date: Thu, 11 Nov 2021 09:57:16 +0900 Subject: [PATCH 1/2] Fix ReadDirFile.ReadDir(n) --- memfs/memfs.go | 7 ++----- memfs/memfs_test.go | 23 ----------------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/memfs/memfs.go b/memfs/memfs.go index 7ba2ffa..d69d0c6 100644 --- a/memfs/memfs.go +++ b/memfs/memfs.go @@ -330,15 +330,12 @@ func (f *MemFile) ReadDir(n int) ([]fs.DirEntry, error) { } max := len(f.dirEntries) if f.dirIndex >= max { - if n == -1 { + if n <= 0 { return nil, nil } return nil, io.EOF } - if n == 0 { - return nil, nil - } - if n == -1 { + if n <= 0 { n = max - f.dirIndex } end := f.dirIndex + n diff --git a/memfs/memfs_test.go b/memfs/memfs_test.go index ac33442..bd75107 100644 --- a/memfs/memfs_test.go +++ b/memfs/memfs_test.go @@ -513,26 +513,3 @@ func TestMemFile_ReadDir_Errors(t *testing.T) { t.Fatalf(`Fatal ReadDir(1) returns no error`) } } - -func TestMemFile_ReadDir0(t *testing.T) { - fsys := newMemFSTest(t) - dir := "dir0" - - f, err := fsys.Open(dir) - if err != nil { - t.Fatal(err) - } - - memf, ok := f.(*MemFile) - if !ok { - t.Fatalf(`Fatal not MemFile: %#v`, f) - } - - entries, err := memf.ReadDir(0) - if err != nil { - t.Fatal(err) - } - if len(entries) != 0 { - t.Errorf(`Error ReadDir(0) returns unknown entries %v`, entries) - } -} From edeafad587d16d990873e4cacce46bc16a6f8c82 Mon Sep 17 00:00:00 2001 From: uz Date: Thu, 11 Nov 2021 09:57:52 +0900 Subject: [PATCH 2/2] Use v for *value instead of e --- memfs/store.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/memfs/store.go b/memfs/store.go index 5a5917f..b99c840 100644 --- a/memfs/store.go +++ b/memfs/store.go @@ -23,39 +23,39 @@ var ( _ fs.FileInfo = (*value)(nil) ) -func (e *value) Name() string { - return filepath.Base(e.name) +func (v *value) Name() string { + return filepath.Base(v.name) } -func (e *value) Size() int64 { - if e.isDir { +func (v *value) Size() int64 { + if v.isDir { return 0 } - return int64(len(e.data)) + return int64(len(v.data)) } -func (e *value) Mode() fs.FileMode { - return e.mode +func (v *value) Mode() fs.FileMode { + return v.mode } -func (e *value) ModTime() time.Time { - return e.modTime +func (v *value) ModTime() time.Time { + return v.modTime } -func (e *value) IsDir() bool { - return e.isDir +func (v *value) IsDir() bool { + return v.isDir } -func (e *value) Sys() interface{} { +func (v *value) Sys() interface{} { return nil } -func (e *value) Type() fs.FileMode { - return e.mode +func (v *value) Type() fs.FileMode { + return v.mode } -func (e *value) Info() (fs.FileInfo, error) { - return e, nil +func (v *value) Info() (fs.FileInfo, error) { + return v, nil } // Store represents an in-memory key value store.