1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:24:39 -07:00

syscall: support more flags when opening directories on Windows

syscall.Open was artificially limiting the flags that were eligible
to open directories on Windows. This change extend the cases where we
pass FILE_FLAG_BACKUP_SEMANTICS to all flag combinations allowed by
Unix.

Change-Id: Ia7c083bcba070f92ea61c6d67487bdefd0d99546
Reviewed-on: https://go-review.googlesource.com/c/go/+/619295
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
qmuntal 2024-10-10 11:56:56 +02:00 committed by Quim Muntal
parent 9cc737d482
commit d20a4c2403
2 changed files with 6 additions and 4 deletions

View File

@ -388,8 +388,10 @@ func Open(name string, flag int, perm uint32) (fd Handle, err error) {
if perm&S_IWRITE == 0 {
attrs = FILE_ATTRIBUTE_READONLY
}
if createmode == OPEN_EXISTING && access == GENERIC_READ {
// Necessary for opening directory handles.
if flag&O_WRONLY == 0 && flag&O_RDWR == 0 {
// We might be opening or creating a directory.
// CreateFile requires FILE_FLAG_BACKUP_SEMANTICS
// to work with directories.
attrs |= FILE_FLAG_BACKUP_SEMANTICS
}
if flag&O_SYNC != 0 {

View File

@ -24,8 +24,8 @@ func TestOpen_Dir(t *testing.T) {
err error
}{
{syscall.O_RDONLY, nil},
{syscall.O_CREAT, syscall.ERROR_ACCESS_DENIED}, // TODO(qmuntal): should be allowed.
{syscall.O_RDONLY | syscall.O_CREAT, syscall.ERROR_ACCESS_DENIED}, // TODO(qmuntal): should be allowed.
{syscall.O_CREAT, nil},
{syscall.O_RDONLY | syscall.O_CREAT, nil},
{syscall.O_RDONLY | syscall.O_TRUNC, syscall.ERROR_ACCESS_DENIED},
{syscall.O_WRONLY | syscall.O_RDWR, syscall.EISDIR},
{syscall.O_WRONLY, syscall.EISDIR},