aboutsummaryrefslogtreecommitdiff
path: root/src/syscall
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/syscall
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/syscall')
-rw-r--r--src/syscall/fs_js.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/syscall/fs_js.go b/src/syscall/fs_js.go
index f7079e9d09..16d9f58b8c 100644
--- a/src/syscall/fs_js.go
+++ b/src/syscall/fs_js.go
@@ -34,6 +34,7 @@ var (
type jsFile struct {
path string
entries []string
+ dirIdx int // entries[:dirIdx] have already been returned in ReadDirent
pos int64
seeked bool
}
@@ -141,8 +142,8 @@ func ReadDirent(fd int, buf []byte) (int, error) {
}
n := 0
- for len(f.entries) > 0 {
- entry := f.entries[0]
+ for f.dirIdx < len(f.entries) {
+ entry := f.entries[f.dirIdx]
l := 2 + len(entry)
if l > len(buf) {
break
@@ -152,7 +153,7 @@ func ReadDirent(fd int, buf []byte) (int, error) {
copy(buf[2:], entry)
buf = buf[l:]
n += l
- f.entries = f.entries[1:]
+ f.dirIdx++
}
return n, nil
@@ -470,6 +471,7 @@ func Seek(fd int, offset int64, whence int) (int64, error) {
}
f.seeked = true
+ f.dirIdx = 0 // Reset directory read position. See issue 35767.
f.pos = newPos
return newPos, nil
}