Commit 4ca59a01 authored by Shenghou Ma's avatar Shenghou Ma

os: remove document duplication in error predicate functions

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5783092
parent e24d99d0
...@@ -42,3 +42,21 @@ func NewSyscallError(syscall string, err error) error { ...@@ -42,3 +42,21 @@ func NewSyscallError(syscall string, err error) error {
} }
return &SyscallError{syscall, err} return &SyscallError{syscall, err}
} }
// IsExist returns whether the error is known to report that a file already exists.
// It is satisfied by ErrExist as well as some syscall errors.
func IsExist(err error) bool {
return isExist(err)
}
// IsNotExist returns whether the error is known to report that a file does not exist.
// It is satisfied by ErrNotExist as well as some syscall errors.
func IsNotExist(err error) bool {
return isNotExist(err)
}
// IsPermission returns whether the error is known to report that permission is denied.
// It is satisfied by ErrPermission as well as some syscall errors.
func IsPermission(err error) bool {
return isPermission(err)
}
...@@ -4,24 +4,21 @@ ...@@ -4,24 +4,21 @@
package os package os
// IsExist returns whether the error is known to report that a file already exists. func isExist(err error) bool {
func IsExist(err error) bool {
if pe, ok := err.(*PathError); ok { if pe, ok := err.(*PathError); ok {
err = pe.Err err = pe.Err
} }
return contains(err.Error(), " exists") return contains(err.Error(), " exists")
} }
// IsNotExist returns whether the error is known to report that a file does not exist. func isNotExist(err error) bool {
func IsNotExist(err error) bool {
if pe, ok := err.(*PathError); ok { if pe, ok := err.(*PathError); ok {
err = pe.Err err = pe.Err
} }
return contains(err.Error(), "does not exist") return contains(err.Error(), "does not exist")
} }
// IsPermission returns whether the error is known to report that permission is denied. func isPermission(err error) bool {
func IsPermission(err error) bool {
if pe, ok := err.(*PathError); ok { if pe, ok := err.(*PathError); ok {
err = pe.Err err = pe.Err
} }
......
...@@ -8,27 +8,21 @@ package os ...@@ -8,27 +8,21 @@ package os
import "syscall" import "syscall"
// IsExist returns whether the error is known to report that a file already exists. func isExist(err error) bool {
// It is satisfied by ErrExist as well as some syscall errors.
func IsExist(err error) bool {
if pe, ok := err.(*PathError); ok { if pe, ok := err.(*PathError); ok {
err = pe.Err err = pe.Err
} }
return err == syscall.EEXIST || err == ErrExist return err == syscall.EEXIST || err == ErrExist
} }
// IsNotExist returns whether the error is known to report that a file does not exist. func isNotExist(err error) bool {
// It is satisfied by ErrNotExist as well as some syscall errors.
func IsNotExist(err error) bool {
if pe, ok := err.(*PathError); ok { if pe, ok := err.(*PathError); ok {
err = pe.Err err = pe.Err
} }
return err == syscall.ENOENT || err == ErrNotExist return err == syscall.ENOENT || err == ErrNotExist
} }
// IsPermission returns whether the error is known to report that permission is denied. func isPermission(err error) bool {
// It is satisfied by ErrPermission as well as some syscall errors.
func IsPermission(err error) bool {
if pe, ok := err.(*PathError); ok { if pe, ok := err.(*PathError); ok {
err = pe.Err err = pe.Err
} }
......
...@@ -6,9 +6,7 @@ package os ...@@ -6,9 +6,7 @@ package os
import "syscall" import "syscall"
// IsExist returns whether the error is known to report that a file already exists. func isExist(err error) bool {
// It is satisfied by ErrExist as well as some syscall errors.
func IsExist(err error) bool {
if pe, ok := err.(*PathError); ok { if pe, ok := err.(*PathError); ok {
err = pe.Err err = pe.Err
} }
...@@ -16,18 +14,14 @@ func IsExist(err error) bool { ...@@ -16,18 +14,14 @@ func IsExist(err error) bool {
err == syscall.ERROR_FILE_EXISTS || err == ErrExist err == syscall.ERROR_FILE_EXISTS || err == ErrExist
} }
// IsNotExist returns whether the error is known to report that a file does not exist. func isNotExist(err error) bool {
// It is satisfied by ErrNotExist as well as some syscall errors.
func IsNotExist(err error) bool {
if pe, ok := err.(*PathError); ok { if pe, ok := err.(*PathError); ok {
err = pe.Err err = pe.Err
} }
return err == syscall.ENOENT || err == ErrNotExist return err == syscall.ENOENT || err == ErrNotExist
} }
// IsPermission returns whether the error is known to report that permission is denied. func isPermission(err error) bool {
// It is satisfied by ErrPermission as well as some syscall errors.
func IsPermission(err error) bool {
if pe, ok := err.(*PathError); ok { if pe, ok := err.(*PathError); ok {
err = pe.Err err = pe.Err
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment