mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
syscall,os: move flags validation from os.OpenFile to syscall.Open
syscall.Open is the functions that maps Unix/Go flags into Windows concepts. Part of the flag validation logic was still implemented in os.OpenFile, move it to syscall.Open for consistency. A nice side effect is that we don't have to translate the file name twice in case of an access denied error. Change-Id: I32c647a9a2a066277c78f53bacb45fb3036f6353 Reviewed-on: https://go-review.googlesource.com/c/go/+/619275 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
0a1c6e3076
commit
39fbc4c29a
3 changed files with 31 additions and 30 deletions
|
|
@ -398,6 +398,13 @@ func Open(path string, mode int, perm uint32) (fd Handle, err error) {
|
|||
}
|
||||
h, err := CreateFile(pathp, access, sharemode, sa, createmode, attrs, 0)
|
||||
if err != nil {
|
||||
if err == ERROR_ACCESS_DENIED && (mode&O_WRONLY != 0 || mode&O_RDWR != 0) {
|
||||
// We should return EISDIR when we are trying to open a directory with write access.
|
||||
fa, e1 := GetFileAttributes(pathp)
|
||||
if e1 == nil && fa&FILE_ATTRIBUTE_DIRECTORY != 0 {
|
||||
err = EISDIR
|
||||
}
|
||||
}
|
||||
return InvalidHandle, err
|
||||
}
|
||||
if mode&O_TRUNC == O_TRUNC {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue