Skip to content

Commit

Permalink
syscall: add O_DIRECTORY for js
Browse files Browse the repository at this point in the history
Change-Id: I2022fa27b072f9b34413a04a794aeb6d3c02166c
Reviewed-on: https://go-review.googlesource.com/c/go/+/606658
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
  • Loading branch information
kolyshkin authored and gopherbot committed Aug 21, 2024
1 parent 92dd056 commit f0f4e2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
16 changes: 10 additions & 6 deletions src/syscall/fs_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ var constants = jsFS.Get("constants")
var uint8Array = js.Global().Get("Uint8Array")

var (
nodeWRONLY = constants.Get("O_WRONLY").Int()
nodeRDWR = constants.Get("O_RDWR").Int()
nodeCREATE = constants.Get("O_CREAT").Int()
nodeTRUNC = constants.Get("O_TRUNC").Int()
nodeAPPEND = constants.Get("O_APPEND").Int()
nodeEXCL = constants.Get("O_EXCL").Int()
nodeWRONLY = constants.Get("O_WRONLY").Int()
nodeRDWR = constants.Get("O_RDWR").Int()
nodeCREATE = constants.Get("O_CREAT").Int()
nodeTRUNC = constants.Get("O_TRUNC").Int()
nodeAPPEND = constants.Get("O_APPEND").Int()
nodeEXCL = constants.Get("O_EXCL").Int()
nodeDIRECTORY = constants.Get("O_DIRECTORY").Int()
)

type jsFile struct {
Expand Down Expand Up @@ -83,6 +84,9 @@ func Open(path string, openmode int, perm uint32) (int, error) {
if openmode&O_SYNC != 0 {
return 0, errors.New("syscall.Open: O_SYNC is not supported by js/wasm")
}
if openmode&O_DIRECTORY != 0 {
flags |= nodeDIRECTORY
}

jsFD, err := fsCall("open", path, flags, perm)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions src/syscall/syscall_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ const (
O_WRONLY = 1
O_RDWR = 2

O_CREAT = 0100
O_CREATE = O_CREAT
O_TRUNC = 01000
O_APPEND = 02000
O_EXCL = 0200
O_SYNC = 010000
O_CREAT = 0100
O_CREATE = O_CREAT
O_TRUNC = 01000
O_APPEND = 02000
O_EXCL = 0200
O_SYNC = 010000
O_DIRECTORY = 020000

O_CLOEXEC = 0
)
Expand Down

0 comments on commit f0f4e2d

Please sign in to comment.