diff options
Diffstat (limited to 'libgo/go/syscall/fs_js.go')
-rw-r--r-- | libgo/go/syscall/fs_js.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/libgo/go/syscall/fs_js.go b/libgo/go/syscall/fs_js.go index 1b835c5..16d9f58 100644 --- a/libgo/go/syscall/fs_js.go +++ b/libgo/go/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 @@ -259,7 +260,7 @@ func Lchown(path string, uid, gid int) error { if err := checkPath(path); err != nil { return err } - if jsFS.Get("lchown") == js.Undefined() { + if jsFS.Get("lchown").IsUndefined() { // fs.lchown is unavailable on Linux until Node.js 10.6.0 // TODO(neelance): remove when we require at least this Node.js version return ENOSYS @@ -404,6 +405,14 @@ func Write(fd int, b []byte) (int, error) { return n, err } + if faketime && (fd == 1 || fd == 2) { + n := faketimeWrite(fd, b) + if n < 0 { + return 0, errnoErr(Errno(-n)) + } + return n, nil + } + buf := uint8Array.New(len(b)) js.CopyBytesToJS(buf, b) n, err := fsCall("write", fd, buf, 0, len(b), nil) @@ -462,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 } @@ -489,7 +499,7 @@ func fsCall(name string, args ...interface{}) (js.Value, error) { var res callResult if len(args) >= 1 { // on Node.js 8, fs.utimes calls the callback without any arguments - if jsErr := args[0]; jsErr != js.Null() { + if jsErr := args[0]; !jsErr.IsNull() { res.err = mapJSError(jsErr) } } |