Skip to content

Commit 106ebe2

Browse files
committed
file/readdir: Always populate error on empty slace
Ref golang#16919
1 parent e6f9f39 commit 106ebe2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/os/dir.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package os
66

7+
import "errors"
8+
79
// Readdir reads the contents of the directory associated with file and
810
// returns a slice of up to n FileInfo values, as would be returned
911
// by Lstat, in directory order. Subsequent calls on the same file will yield
@@ -23,7 +25,11 @@ func (f *File) Readdir(n int) ([]FileInfo, error) {
2325
if f == nil {
2426
return nil, ErrInvalid
2527
}
26-
return f.readdir(n)
28+
fi, err := f.readdir(n)
29+
if err == nil && len(fi) == 0 && n > 0 {
30+
err = errors.New("no files found")
31+
}
32+
return fi, err
2733
}
2834

2935
// Readdirnames reads and returns a slice of names from the directory f.

0 commit comments

Comments
 (0)