-
Notifications
You must be signed in to change notification settings - Fork 51
Closed
Description
Version
v5.4.1
Description
memfs.New().ReadDir("asdf")
returns nil, nil
instead of nil, <directory-not-found-err>
.
Minimal example
func TestMemoryReadDir(t *testing.T) {
if _, err := osfs.New("/tmp").ReadDir("asdf"); err == nil {
t.Fatal("osfs: expected error; found <nil>")
} else {
t.Logf("osfs: error was correctly returned!")
}
if _, err := memfs.New().ReadDir("asdf"); err == nil {
t.Fatal("memfs: expected error; found <nil>")
} else {
t.Logf("memfs: error was correctly returned!")
}
}
// Output
// osfs: error was correctly returned!
// memfs: expected error; found <nil>
Proposed changes
func (fs *Memory) ReadDir(path string) ([]os.FileInfo, error) {
if f, has := fs.s.Get(path); has {
if target, isLink := fs.resolveLink(path, f); isLink {
return fs.ReadDir(target)
}
+ } else {
+ return nil, &fs.PathError{Op: "open", Path: path, Err: unix.ENOENT}
}
var entries []os.FileInfo
for _, f := range fs.s.Children(path) {
fi, _ := f.Stat()
entries = append(entries, fi)
}
sort.Sort(ByName(entries))
return entries, nil
}
Metadata
Metadata
Assignees
Labels
No labels