aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2019-12-04 14:58:04 -0800
committerKeith Randall <khr@golang.org>2019-12-05 20:40:38 +0000
commite3c7ffcd957785bc9d3e1f2db9219bd74a96bbb1 (patch)
tree4fa3ddebcbd6746b73109b8d06b28a4f66057ce8 /src/os
parentd72dce87837c96f875d5fa2e26159ef211bce3a0 (diff)
downloadgo-e3c7ffcd957785bc9d3e1f2db9219bd74a96bbb1.tar.xz
os: reset dirinfo when seeking on Darwin
The first Readdirnames calls opendir and caches the result. The behavior of that cached opendir result isn't specified on a seek of the underlying fd. Free the opendir result on a seek so that we'll allocate a new one the next time around. Also fix wasm behavior in this regard, so that a seek to the file start resets the Readdirnames position, regardless of platform. p.s. I hate the Readdirnames API. Fixes #35767. Change-Id: Ieffb61b3c5cdd42591f69ab13f932003966f2297 Reviewed-on: https://go-review.googlesource.com/c/go/+/209961 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/os')
-rw-r--r--src/os/dir_darwin.go10
-rw-r--r--src/os/dir_unix.go2
-rw-r--r--src/os/file_unix.go1
3 files changed, 13 insertions, 0 deletions
diff --git a/src/os/dir_darwin.go b/src/os/dir_darwin.go
index 2f9ba78d68..a274dd1268 100644
--- a/src/os/dir_darwin.go
+++ b/src/os/dir_darwin.go
@@ -24,6 +24,16 @@ func (d *dirInfo) close() {
d.dir = 0
}
+func (f *File) seekInvalidate() {
+ if f.dirinfo == nil {
+ return
+ }
+ // Free cached dirinfo, so we allocate a new one if we
+ // access this file as a directory again. See #35767.
+ f.dirinfo.close()
+ f.dirinfo = nil
+}
+
func (f *File) readdirnames(n int) (names []string, err error) {
if f.dirinfo == nil {
dir, call, errno := f.pfd.OpenDir()
diff --git a/src/os/dir_unix.go b/src/os/dir_unix.go
index e0c4989756..2856a2dc0f 100644
--- a/src/os/dir_unix.go
+++ b/src/os/dir_unix.go
@@ -26,6 +26,8 @@ const (
func (d *dirInfo) close() {}
+func (f *File) seekInvalidate() {}
+
func (f *File) readdirnames(n int) (names []string, err error) {
// If this file has no dirinfo, create one.
if f.dirinfo == nil {
diff --git a/src/os/file_unix.go b/src/os/file_unix.go
index 31c43eb61e..6945937fd6 100644
--- a/src/os/file_unix.go
+++ b/src/os/file_unix.go
@@ -295,6 +295,7 @@ func (f *File) pwrite(b []byte, off int64) (n int, err error) {
// relative to the current offset, and 2 means relative to the end.
// It returns the new offset and an error, if any.
func (f *File) seek(offset int64, whence int) (ret int64, err error) {
+ f.seekInvalidate()
ret, err = f.pfd.Seek(offset, whence)
runtime.KeepAlive(f)
return ret, err