MCPcopy Index your code
hub / github.com/cockroachdb/errors / IsExist

Function IsExist

oserror/oserror.go:66–82  ·  view source on GitHub ↗

IsExist returns a boolean indicating whether the error is known to report that a file or directory already exists. It is satisfied by ErrExist as well as some syscall errors. This function differs from os.IsExist() in that it can identify an error through wrapping layers.

(err error)

Source from the content-addressed store, hash-verified

64// This function differs from os.IsExist() in that it
65// can identify an error through wrapping layers.
66func IsExist(err error) bool {
67 // errors.Is() is not able to peek through os.SyscallError,
68 // whereas os.IsExist() can. Conversely, os.IsExist()
69 // cannot peek through Unwrap, whereas errors.Is() can. So we
70 // need to try both.
71 if errors.Is(err, ErrExist) || os.IsExist(errors.UnwrapAll(err)) {
72 return true
73 }
74 // If a syscall errno representing ErrExist was encoded on a
75 // different platform, and decoded here, then it will show up as
76 // neither a syscall errno here nor an ErrExist; instead it
77 // shows up as an OpaqueErrno. We test this here.
78 if o := (*errbase.OpaqueErrno)(nil); errors.As(err, &o) {
79 return o.Is(ErrExist)
80 }
81 return false
82}
83
84// IsNotExist returns a boolean indicating whether the error is known to
85// report that a file or directory does not exist. It is satisfied by

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…