summaryrefslogtreecommitdiffhomepage
path: root/pkg/errors/linuxerr
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-06-22 22:57:48 +0000
committergVisor bot <gvisor-bot@google.com>2021-06-22 22:57:48 +0000
commitc6031eb481baf57849c45c6ffde27efc89398c4c (patch)
tree1cd27d85a44a8a5fe8f210ef3feed3e35699cb75 /pkg/errors/linuxerr
parentd909242b0d797db387131912b51373fda7608e95 (diff)
parente1dc1c78e7a523fc64ca28bed60a9a40ea1de46a (diff)
Merge release-20210614.0-14-ge1dc1c78e (automated)
Diffstat (limited to 'pkg/errors/linuxerr')
-rw-r--r--pkg/errors/linuxerr/linuxerr.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/pkg/errors/linuxerr/linuxerr.go b/pkg/errors/linuxerr/linuxerr.go
index bbdcdecd0..9246f2e89 100644
--- a/pkg/errors/linuxerr/linuxerr.go
+++ b/pkg/errors/linuxerr/linuxerr.go
@@ -20,6 +20,7 @@ package linuxerr
import (
"fmt"
+ "golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/abi/linux/errno"
"gvisor.dev/gvisor/pkg/errors"
)
@@ -325,3 +326,22 @@ func ErrorFromErrno(e errno.Errno) *errors.Error {
}
panic(fmt.Sprintf("invalid error requested with errno: %d", e))
}
+
+// Equals compars a linuxerr to a given error
+// TODO(b/34162363): Remove when syserror is removed.
+func Equals(e *errors.Error, err error) bool {
+ if err == nil {
+ return e == NOERROR || e == nil
+ }
+ if e == nil {
+ return err == NOERROR || err == unix.Errno(0)
+ }
+
+ switch err.(type) {
+ case *errors.Error:
+ return e == err
+ case unix.Errno, error:
+ return unix.Errno(e.Errno()) == err
+ }
+ return false
+}