error_unix.go 1.03 KB
Newer Older
1 2 3 4
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

5
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
6

7 8
package os

9
import "syscall"
10

11
func isExist(err error) bool {
12 13 14 15 16 17
	switch pe := err.(type) {
	case nil:
		return false
	case *PathError:
		err = pe.Err
	case *LinkError:
18
		err = pe.Err
19 20
	case *SyscallError:
		err = pe.Err
21
	}
22
	return err == syscall.EEXIST || err == syscall.ENOTEMPTY || err == ErrExist
23 24
}

25
func isNotExist(err error) bool {
26 27 28 29 30 31
	switch pe := err.(type) {
	case nil:
		return false
	case *PathError:
		err = pe.Err
	case *LinkError:
32
		err = pe.Err
33 34
	case *SyscallError:
		err = pe.Err
35 36 37 38
	}
	return err == syscall.ENOENT || err == ErrNotExist
}

39
func isPermission(err error) bool {
40 41 42 43 44 45
	switch pe := err.(type) {
	case nil:
		return false
	case *PathError:
		err = pe.Err
	case *LinkError:
46
		err = pe.Err
47 48
	case *SyscallError:
		err = pe.Err
49 50 51
	}
	return err == syscall.EACCES || err == syscall.EPERM || err == ErrPermission
}