From 400e6b68b55e20f49f10aaf69df5e3b298b02ad7 Mon Sep 17 00:00:00 2001
From: Kir Kolyshkin <kolyshkin@gmail.com>
Date: Tue, 28 May 2024 17:23:15 -0700
Subject: [PATCH] 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>
---
 src/os/file_unix.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/os/file_unix.go b/src/os/file_unix.go
index 37bfaa1a72d..73069faa567 100644
--- a/src/os/file_unix.go
+++ b/src/os/file_unix.go
@@ -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 {
-- 
GitLab