Skip to content

Commit

Permalink
os: don't request read access from CreateFile in Stat
Browse files Browse the repository at this point in the history
CL 448897 changed os.Stat to request GENERIC_READ access when using
CreateFile to examine a file. This is unnecessary; access flags of 0
will permit examining file metadata even if the file isn't readable.
Revert to the old behavior here.

For #56217

Change-Id: I09220b3bbee304bd89f4a94ec9b0af42042b7773
Reviewed-on: https://go-review.googlesource.com/c/go/+/450296
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
Run-TryBot: Quim Muntal <[email protected]>
  • Loading branch information
neild committed Nov 14, 2022
1 parent 6234e46 commit 24fc640
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/os/stat_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ func stat(funcname, name string, createFileAttrs uint32) (FileInfo, error) {
}

// Finally use CreateFile.
h, err := syscall.CreateFile(namep,
syscall.GENERIC_READ,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE,
nil,
syscall.OPEN_EXISTING,
createFileAttrs, 0)
h, err := syscall.CreateFile(namep, 0, 0, nil,
syscall.OPEN_EXISTING, createFileAttrs, 0)
if err != nil {
return nil, &PathError{Op: "CreateFile", Path: name, Err: err}
}
Expand Down

0 comments on commit 24fc640

Please sign in to comment.