Make unix Readdir and windows Readdirnames return partially successful results on error.

Make plan 9 Readdir & Readdirnames return os.EOF at end.
Also fix typos in the unix and windows comments.

R=golang-dev, fshahriar, bradfitz, rsc, r
CC=golang-dev
https://golang.org/cl/4557053
This commit is contained in:
Yuval Pavel Zholkover 2011-06-01 13:12:37 +10:00 committed by Rob Pike
parent 73d57642a4
commit f74f50e046
4 changed files with 49 additions and 45 deletions

View file

@ -69,12 +69,12 @@ func (file *File) Stat() (fi *FileInfo, err Error) {
}
// Readdir reads the contents of the directory associated with file and
// returns an array of up to count FileInfo structures, as would be returned
// returns an array of up to n FileInfo structures, as would be returned
// by Lstat, in directory order. Subsequent calls on the same file will yield
// further FileInfos.
//
// If n > 0, Readdir returns at most n names. In this case, if
// Readdirnames returns an empty slice, it will return a non-nil error
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if
// Readdir returns an empty slice, it will return a non-nil error
// explaining why. At the end of a directory, the error is os.EOF.
//
// If n <= 0, Readdir returns all the FileInfo from the directory in
@ -89,11 +89,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
dirname = "."
}
dirname += "/"
wantAll := n < 0
names, namesErr := file.Readdirnames(n)
if namesErr != nil && !wantAll {
return nil, namesErr
}
names, err := file.Readdirnames(n)
fi = make([]FileInfo, len(names))
for i, filename := range names {
fip, err := Lstat(dirname + filename)
@ -103,9 +99,6 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
fi[i] = *fip
}
}
if !wantAll && namesErr != EOF {
err = namesErr
}
return
}