]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: add O_DIRECTORY for js
authorKir Kolyshkin <kolyshkin@gmail.com>
Tue, 20 Aug 2024 00:13:00 +0000 (17:13 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 21 Aug 2024 18:23:25 +0000 (18:23 +0000)
Change-Id: I2022fa27b072f9b34413a04a794aeb6d3c02166c
Reviewed-on: https://go-review.googlesource.com/c/go/+/606658
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/syscall/fs_js.go
src/syscall/syscall_js.go

index b6138ebeb1ed530c7d32bb902e9fef4a04b8304a..111ce4f5c1e7c501f6aa22e18f07d231642f4cd4 100644 (file)
@@ -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 {
@@ -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 {
index 0e529e0343738aea14fbec9884da47b5559f8801..c320e34f2601cb0f922137ac908f955601d9de78 100644 (file)
@@ -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
 )