Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion memfs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"sort"
"strings"
"syscall"
"time"

"github.com/go-git/go-billy/v5"
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions memfs/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"runtime"
"testing"

"github.com/go-git/go-billy/v5"
Expand Down Expand Up @@ -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)
Expand Down