MCPcopy Create free account
hub / github.com/cockroachdb/errors / IsPermission

Function IsPermission

oserror/oserror.go:42–58  ·  view source on GitHub ↗

IsPermission returns a boolean indicating whether the error is known to report that permission is denied. It is satisfied by ErrPermission as well as some syscall errors. This function differs from os.IsPermission() in that it can identify an error through wrapping layers.

(err error)

Source from the content-addressed store, hash-verified

40// This function differs from os.IsPermission() in that it
41// can identify an error through wrapping layers.
42func IsPermission(err error) bool {
43 // errors.Is() is not able to peek through os.SyscallError,
44 // whereas os.IsPermission() can. Conversely, os.IsPermission()
45 // cannot peek through Unwrap, whereas errors.Is() can. So we
46 // need to try both.
47 if errors.Is(err, ErrPermission) || os.IsPermission(errors.UnwrapAll(err)) {
48 return true
49 }
50 // If a syscall errno representing ErrPermission was encoded on a
51 // different platform, and decoded here, then it will show up as
52 // neither a syscall errno here nor an ErrPermission; instead it
53 // shows up as an OpaqueErrno. We test this here.
54 if o := (*errbase.OpaqueErrno)(nil); errors.As(err, &o) {
55 return o.Is(ErrPermission)
56 }
57 return false
58}
59
60// IsExist returns a boolean indicating whether the error is known to report
61// that a file or directory already exists. It is satisfied by ErrExist as

Callers 3

TestAdaptErrnoFunction · 0.92
TestErrorPredicatesUnixFunction · 0.85
TestErrorPredicatesFunction · 0.85

Calls 4

IsFunction · 0.92
UnwrapAllFunction · 0.92
AsFunction · 0.92
IsMethod · 0.45

Tested by 3

TestAdaptErrnoFunction · 0.74
TestErrorPredicatesUnixFunction · 0.68
TestErrorPredicatesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…