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)
| 64 | // This function differs from os.IsExist() in that it |
| 65 | // can identify an error through wrapping layers. |
| 66 | func 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 |
searching dependent graphs…