# EBADF - guard agains macOS `stat` throwing EBADF
_IGNORED_ERROS = (ENOENT, ENOTDIR, EBADF)
+_IGNORED_WINERRORS = (
+ 21, # ERROR_NOT_READY - drive exists but is not accessible
+)
+
+def _ignore_error(exception):
+ return (getattr(exception, 'errno', None) in _IGNORED_ERROS or
+ getattr(exception, 'winerror', None) in _IGNORED_WINERRORS)
+
+
def _is_wildcard_pattern(pat):
# Whether this pattern needs actual matching using fnmatch, or can
# be looked up directly as a file.
try:
entry_is_dir = entry.is_dir()
except OSError as e:
- if e.errno not in _IGNORED_ERROS:
+ if not _ignore_error(e):
raise
if entry_is_dir and not entry.is_symlink():
path = parent_path._make_child_relpath(entry.name)
try:
self.stat()
except OSError as e:
- if e.errno not in _IGNORED_ERROS:
+ if not _ignore_error(e):
raise
return False
except ValueError:
try:
return S_ISDIR(self.stat().st_mode)
except OSError as e:
- if e.errno not in _IGNORED_ERROS:
+ if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
try:
return S_ISREG(self.stat().st_mode)
except OSError as e:
- if e.errno not in _IGNORED_ERROS:
+ if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
try:
return S_ISLNK(self.lstat().st_mode)
except OSError as e:
- if e.errno not in _IGNORED_ERROS:
+ if not _ignore_error(e):
raise
# Path doesn't exist
return False
try:
return S_ISBLK(self.stat().st_mode)
except OSError as e:
- if e.errno not in _IGNORED_ERROS:
+ if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
try:
return S_ISCHR(self.stat().st_mode)
except OSError as e:
- if e.errno not in _IGNORED_ERROS:
+ if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
try:
return S_ISFIFO(self.stat().st_mode)
except OSError as e:
- if e.errno not in _IGNORED_ERROS:
+ if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
try:
return S_ISSOCK(self.stat().st_mode)
except OSError as e:
- if e.errno not in _IGNORED_ERROS:
+ if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)