Skip to content
Snippets Groups Projects
Commit 75c2e97c authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser
Browse files

syscall: let ENOSYS, ENOTSUP and EOPNOTSUPP implement errors.ErrUnsupported

As suggested by Bryan, also update (Errno).Is on windows to include the
missing oserror cases that are covered on other platforms.

Quoting Bryan:
> Windows syscalls don't actually return those errors, but the dummy Errno
> constants defined on Windows should still have the same meaning as on
> Unix.

Updates #41198

Change-Id: I15441abde4a7ebaa3c6518262c052530cd2add4b
Reviewed-on: https://go-review.googlesource.com/c/go/+/476875


TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: default avatarBryan Mills <bcmills@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: default avatarIan Lance Taylor <iant@google.com>
parent 8377f201
No related branches found
No related tags found
No related merge requests found
...@@ -24,11 +24,6 @@ func syscallIsNotSupported(err error) bool { ...@@ -24,11 +24,6 @@ func syscallIsNotSupported(err error) bool {
var errno syscall.Errno var errno syscall.Errno
if errors.As(err, &errno) { if errors.As(err, &errno) {
switch errno { switch errno {
case syscall.ENOSYS, syscall.ENOTSUP:
// Explicitly not supported.
// TODO(#41198): remove these cases when errors.Is reports that they are
// equivalent to ErrUnsupported.
return true
case syscall.EPERM, syscall.EROFS: case syscall.EPERM, syscall.EROFS:
// User lacks permission: either the call requires root permission and the // User lacks permission: either the call requires root permission and the
// user is not root, or the call is denied by a container security policy. // user is not root, or the call is denied by a container security policy.
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package syscall package syscall
import ( import (
errorspkg "errors"
"internal/itoa" "internal/itoa"
"internal/oserror" "internal/oserror"
"sync" "sync"
...@@ -47,8 +48,8 @@ const PathMax = 256 ...@@ -47,8 +48,8 @@ const PathMax = 256
// err = errno // err = errno
// } // }
// //
// Errno values can be tested against error values from the os package // Errno values can be tested against error values using errors.Is.
// using errors.Is. For example: // For example:
// //
// _, _, err := syscall.Syscall(...) // _, _, err := syscall.Syscall(...)
// if errors.Is(err, fs.ErrNotExist) ... // if errors.Is(err, fs.ErrNotExist) ...
...@@ -72,6 +73,8 @@ func (e Errno) Is(target error) bool { ...@@ -72,6 +73,8 @@ func (e Errno) Is(target error) bool {
return e == EEXIST || e == ENOTEMPTY return e == EEXIST || e == ENOTEMPTY
case oserror.ErrNotExist: case oserror.ErrNotExist:
return e == ENOENT return e == ENOENT
case errorspkg.ErrUnsupported:
return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
} }
return false return false
} }
......
...@@ -23,8 +23,8 @@ const bitSize16 = 2 ...@@ -23,8 +23,8 @@ const bitSize16 = 2
// ErrorString implements Error's String method by returning itself. // ErrorString implements Error's String method by returning itself.
// //
// ErrorString values can be tested against error values from the os package // ErrorString values can be tested against error values using errors.Is.
// using errors.Is. For example: // For example:
// //
// _, _, err := syscall.Syscall(...) // _, _, err := syscall.Syscall(...)
// if errors.Is(err, fs.ErrNotExist) ... // if errors.Is(err, fs.ErrNotExist) ...
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package syscall package syscall
import ( import (
errorspkg "errors"
"internal/bytealg" "internal/bytealg"
"internal/itoa" "internal/itoa"
"internal/oserror" "internal/oserror"
...@@ -97,8 +98,8 @@ func (m *mmapper) Munmap(data []byte) (err error) { ...@@ -97,8 +98,8 @@ func (m *mmapper) Munmap(data []byte) (err error) {
// err = errno // err = errno
// } // }
// //
// Errno values can be tested against error values from the os package // Errno values can be tested against error values using errors.Is.
// using errors.Is. For example: // For example:
// //
// _, _, err := syscall.Syscall(...) // _, _, err := syscall.Syscall(...)
// if errors.Is(err, fs.ErrNotExist) ... // if errors.Is(err, fs.ErrNotExist) ...
...@@ -122,6 +123,8 @@ func (e Errno) Is(target error) bool { ...@@ -122,6 +123,8 @@ func (e Errno) Is(target error) bool {
return e == EEXIST || e == ENOTEMPTY return e == EEXIST || e == ENOTEMPTY
case oserror.ErrNotExist: case oserror.ErrNotExist:
return e == ENOENT return e == ENOENT
case errorspkg.ErrUnsupported:
return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
} }
return false return false
} }
......
...@@ -103,8 +103,8 @@ func UTF16PtrFromString(s string) (*uint16, error) { ...@@ -103,8 +103,8 @@ func UTF16PtrFromString(s string) (*uint16, error) {
// Errno is the Windows error number. // Errno is the Windows error number.
// //
// Errno values can be tested against error values from the os package // Errno values can be tested against error values using errors.Is.
// using errors.Is. For example: // For example:
// //
// _, _, err := syscall.Syscall(...) // _, _, err := syscall.Syscall(...)
// if errors.Is(err, fs.ErrNotExist) ... // if errors.Is(err, fs.ErrNotExist) ...
...@@ -147,17 +147,25 @@ const _ERROR_BAD_NETPATH = Errno(53) ...@@ -147,17 +147,25 @@ const _ERROR_BAD_NETPATH = Errno(53)
func (e Errno) Is(target error) bool { func (e Errno) Is(target error) bool {
switch target { switch target {
case oserror.ErrPermission: case oserror.ErrPermission:
return e == ERROR_ACCESS_DENIED return e == ERROR_ACCESS_DENIED ||
e == EACCES ||
e == EPERM
case oserror.ErrExist: case oserror.ErrExist:
return e == ERROR_ALREADY_EXISTS || return e == ERROR_ALREADY_EXISTS ||
e == ERROR_DIR_NOT_EMPTY || e == ERROR_DIR_NOT_EMPTY ||
e == ERROR_FILE_EXISTS e == ERROR_FILE_EXISTS ||
e == EEXIST ||
e == ENOTEMPTY
case oserror.ErrNotExist: case oserror.ErrNotExist:
return e == ERROR_FILE_NOT_FOUND || return e == ERROR_FILE_NOT_FOUND ||
e == _ERROR_BAD_NETPATH || e == _ERROR_BAD_NETPATH ||
e == ERROR_PATH_NOT_FOUND e == ERROR_PATH_NOT_FOUND ||
e == ENOENT
case errorspkg.ErrUnsupported: case errorspkg.ErrUnsupported:
return e == EWINDOWS return e == ENOSYS ||
e == ENOTSUP ||
e == EOPNOTSUPP ||
e == EWINDOWS
} }
return false return false
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment