summaryrefslogtreecommitdiff
path: root/libgo/go/os/error_plan9.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/os/error_plan9.go')
-rw-r--r--libgo/go/os/error_plan9.go48
1 files changed, 16 insertions, 32 deletions
diff --git a/libgo/go/os/error_plan9.go b/libgo/go/os/error_plan9.go
index 2dc6b39c395..a67343981e2 100644
--- a/libgo/go/os/error_plan9.go
+++ b/libgo/go/os/error_plan9.go
@@ -5,46 +5,30 @@
package os
func isExist(err error) bool {
- switch pe := err.(type) {
- case nil:
- return false
- case *PathError:
- err = pe.Err
- case *LinkError:
- err = pe.Err
- case *SyscallError:
- err = pe.Err
- }
- return contains(err.Error(), " exists")
+ return checkErrMessageContent(err, " exists")
}
func isNotExist(err error) bool {
- switch pe := err.(type) {
- case nil:
- return false
- case *PathError:
- err = pe.Err
- case *LinkError:
- err = pe.Err
- case *SyscallError:
- err = pe.Err
- }
- return contains(err.Error(), "does not exist") || contains(err.Error(), "not found") ||
- contains(err.Error(), "has been removed") || contains(err.Error(), "no parent")
+ return checkErrMessageContent(err, "does not exist", "not found",
+ "has been removed", "no parent")
}
func isPermission(err error) bool {
- switch pe := err.(type) {
- case nil:
+ return checkErrMessageContent(err, "permission denied")
+}
+
+// checkErrMessageContent checks if err message contains one of msgs.
+func checkErrMessageContent(err error, msgs ...string) bool {
+ if err == nil {
return false
- case *PathError:
- err = pe.Err
- case *LinkError:
- err = pe.Err
- case *SyscallError:
- err = pe.Err
}
- return contains(err.Error(), "permission denied")
+ err = underlyingError(err)
+ for _, msg := range msgs {
+ if contains(err.Error(), msg) {
+ return true
+ }
+ }
+ return false
}
// contains is a local version of strings.Contains. It knows len(sep) > 1.