error_windows.go 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package os
  5. import "syscall"
  6. func isExist(err error) bool {
  7. switch pe := err.(type) {
  8. case nil:
  9. return false
  10. case *PathError:
  11. err = pe.Err
  12. case *LinkError:
  13. err = pe.Err
  14. }
  15. return err == syscall.ERROR_ALREADY_EXISTS ||
  16. err == syscall.ERROR_FILE_EXISTS || err == ErrExist
  17. }
  18. func isNotExist(err error) bool {
  19. switch pe := err.(type) {
  20. case nil:
  21. return false
  22. case *PathError:
  23. err = pe.Err
  24. case *LinkError:
  25. err = pe.Err
  26. }
  27. return err == syscall.ERROR_FILE_NOT_FOUND ||
  28. err == syscall.ERROR_PATH_NOT_FOUND || err == ErrNotExist
  29. }
  30. func isPermission(err error) bool {
  31. switch pe := err.(type) {
  32. case nil:
  33. return false
  34. case *PathError:
  35. err = pe.Err
  36. case *LinkError:
  37. err = pe.Err
  38. }
  39. return err == syscall.ERROR_ACCESS_DENIED || err == ErrPermission
  40. }