os: openDir: add O_DIRECTORY flag for unix

With this, ReadDir will fail a tad earlier (on open rather than on
readdir syscall). This should be the only effect of this change.

Change-Id: Icf2870f47ea6c19aad29670e78ba9bfcc13c0ac3
Reviewed-on: https://go-review.googlesource.com/c/go/+/588915
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Kir Kolyshkin 2024-05-28 17:23:15 -07:00 committed by Gopher Robot
parent 4f18477db6
commit 400e6b68b5
1 changed files with 1 additions and 1 deletions

View File

@ -306,7 +306,7 @@ func openDirNolog(name string) (*File, error) {
e error
)
ignoringEINTR(func() error {
r, s, e = open(name, O_RDONLY|syscall.O_CLOEXEC, 0)
r, s, e = open(name, O_RDONLY|syscall.O_CLOEXEC|syscall.O_DIRECTORY, 0)
return e
})
if e != nil {