os: implement readdir for darwin and linux

readdir is disabled on linux for 386 and arm until syscall.seek is implemented there.

windows is hard, so leaving that for later.

File src/os/dir_other_go115.go can be deleted when we drop support for go 1.15.

Also adds TestReadNonDir, which was helpful while debugging.
This commit is contained in:
Dan Kegel
2022-01-08 12:28:32 -08:00
committed by Ron Evans
parent 3fa7d6cc40
commit 641a7e5cb9
20 changed files with 972 additions and 67 deletions
+4 -17
View File
@@ -24,6 +24,9 @@ const (
SEEK_END int = io.SeekEnd
)
// lstat is overridden in tests.
var lstat = Lstat
// Mkdir creates a directory. If the operation fails, it will return an error of
// type *PathError.
func Mkdir(path string, perm FileMode) error {
@@ -66,12 +69,6 @@ func RemoveAll(path string) error {
return ErrNotImplemented
}
// File represents an open file descriptor.
type File struct {
handle FileHandle
name string
}
// Name returns the name of the file with which it was opened.
func (f *File) Name() string {
return f.name
@@ -88,7 +85,7 @@ func OpenFile(name string, flag int, perm FileMode) (*File, error) {
if err != nil {
return nil, &PathError{"open", name, err}
}
return &File{name: name, handle: handle}, nil
return NewFile(handle, name), nil
}
// Open opens the file named for reading.
@@ -170,16 +167,6 @@ func (f *File) Close() (err error) {
return
}
// Readdir is a stub, not yet implemented
func (f *File) Readdir(n int) ([]FileInfo, error) {
return nil, &PathError{"readdir", f.name, ErrNotImplemented}
}
// Readdirnames is a stub, not yet implemented
func (f *File) Readdirnames(n int) (names []string, err error) {
return nil, &PathError{"readdirnames", f.name, ErrNotImplemented}
}
// Seek sets the offset for the next Read or Write on file to offset, interpreted
// according to whence: 0 means relative to the origin of the file, 1 means
// relative to the current offset, and 2 means relative to the end.