diff --git a/memfs/memory.go b/memfs/memory.go index dab7396..2e17a3c 100644 --- a/memfs/memory.go +++ b/memfs/memory.go @@ -9,6 +9,7 @@ import ( "path/filepath" "sort" "strings" + "syscall" "time" "github.com/go-git/go-billy/v5" @@ -25,7 +26,7 @@ type Memory struct { tempCount int } -//New returns a new Memory filesystem. +// New returns a new Memory filesystem. func New() billy.Filesystem { fs := &Memory{s: newStorage()} return chroot.New(fs, string(separator)) @@ -133,6 +134,8 @@ func (fs *Memory) ReadDir(path string) ([]os.FileInfo, error) { if target, isLink := fs.resolveLink(path, f); isLink { return fs.ReadDir(target) } + } else { + return nil, &os.PathError{Op: "open", Path: path, Err: syscall.ENOENT} } var entries []os.FileInfo diff --git a/memfs/memory_test.go b/memfs/memory_test.go index b23f7ae..26f74ca 100644 --- a/memfs/memory_test.go +++ b/memfs/memory_test.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "os" + "runtime" "testing" "github.com/go-git/go-billy/v5" @@ -85,6 +86,17 @@ func (s *MemorySuite) TestOrder(c *C) { } } +func (s *MemorySuite) TestNotFound(c *C) { + files, err := s.FS.ReadDir("asdf") + c.Assert(files, HasLen, 0) + // JS / wasip have this error message captalised. + msg := "open /asdf: (N|n)o such file or directory" + if runtime.GOOS == "windows" { + msg = `open \\asdf: The system cannot find the file specified\.` + } + c.Assert(err, ErrorMatches, msg) +} + func (s *MemorySuite) TestTruncateAppend(c *C) { err := util.WriteFile(s.FS, "truncate_append", []byte("file-content"), 0666) c.Assert(err, IsNil)