Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory.ReadDir() should return an error when path isn't found. #38

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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