mirror of https://github.com/golang/go.git
syscall: disable O_DIRECTORY on Windows for js/wasm
O_DIRECTORY is not available on all platforms, as described at
https://nodejs.org/docs/latest/api/fs.html#file-open-constants .
On Windows, only O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR,
O_TRUNC, O_WRONLY, and UV_FS_O_FILEMAP are available.
Fixes #71758
Change-Id: Iacc890ba9a30dcd75eb746ec324fa0c3e368048e
GitHub-Last-Rev: a0160e8fc8
GitHub-Pull-Request: golang/go#71770
Reviewed-on: https://go-review.googlesource.com/c/go/+/650015
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
parent
0bdc792145
commit
ad8b33002b
|
|
@ -29,9 +29,20 @@ var (
|
||||||
nodeTRUNC = constants.Get("O_TRUNC").Int()
|
nodeTRUNC = constants.Get("O_TRUNC").Int()
|
||||||
nodeAPPEND = constants.Get("O_APPEND").Int()
|
nodeAPPEND = constants.Get("O_APPEND").Int()
|
||||||
nodeEXCL = constants.Get("O_EXCL").Int()
|
nodeEXCL = constants.Get("O_EXCL").Int()
|
||||||
nodeDIRECTORY = constants.Get("O_DIRECTORY").Int()
|
|
||||||
|
// NodeJS on Windows does not support O_DIRECTORY, so we default
|
||||||
|
// to -1 and assign it in init if available.
|
||||||
|
// See https://nodejs.org/docs/latest/api/fs.html#file-open-constants.
|
||||||
|
nodeDIRECTORY = -1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
oDir := constants.Get("O_DIRECTORY")
|
||||||
|
if !oDir.IsUndefined() {
|
||||||
|
nodeDIRECTORY = oDir.Int()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type jsFile struct {
|
type jsFile struct {
|
||||||
path string
|
path string
|
||||||
entries []string
|
entries []string
|
||||||
|
|
@ -85,7 +96,11 @@ func Open(path string, openmode int, perm uint32) (int, error) {
|
||||||
return 0, errors.New("syscall.Open: O_SYNC is not supported by js/wasm")
|
return 0, errors.New("syscall.Open: O_SYNC is not supported by js/wasm")
|
||||||
}
|
}
|
||||||
if openmode&O_DIRECTORY != 0 {
|
if openmode&O_DIRECTORY != 0 {
|
||||||
|
if nodeDIRECTORY != -1 {
|
||||||
flags |= nodeDIRECTORY
|
flags |= nodeDIRECTORY
|
||||||
|
} else {
|
||||||
|
return 0, errors.New("syscall.Open: O_DIRECTORY is not supported on Windows")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jsFD, err := fsCall("open", path, flags, perm)
|
jsFD, err := fsCall("open", path, flags, perm)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue