mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-35692: pathlib no longer raises when checking file and directory existence on drives that are not ready (GH-11746)
This commit is contained in:
parent
f75d59e1a8
commit
2f6fae6e51
2 changed files with 20 additions and 9 deletions
|
@ -37,6 +37,15 @@ __all__ = [
|
||||||
# EBADF - guard agains macOS `stat` throwing EBADF
|
# EBADF - guard agains macOS `stat` throwing EBADF
|
||||||
_IGNORED_ERROS = (ENOENT, ENOTDIR, 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):
|
def _is_wildcard_pattern(pat):
|
||||||
# Whether this pattern needs actual matching using fnmatch, or can
|
# Whether this pattern needs actual matching using fnmatch, or can
|
||||||
# be looked up directly as a file.
|
# be looked up directly as a file.
|
||||||
|
@ -535,7 +544,7 @@ class _RecursiveWildcardSelector(_Selector):
|
||||||
try:
|
try:
|
||||||
entry_is_dir = entry.is_dir()
|
entry_is_dir = entry.is_dir()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in _IGNORED_ERROS:
|
if not _ignore_error(e):
|
||||||
raise
|
raise
|
||||||
if entry_is_dir and not entry.is_symlink():
|
if entry_is_dir and not entry.is_symlink():
|
||||||
path = parent_path._make_child_relpath(entry.name)
|
path = parent_path._make_child_relpath(entry.name)
|
||||||
|
@ -1328,7 +1337,7 @@ class Path(PurePath):
|
||||||
try:
|
try:
|
||||||
self.stat()
|
self.stat()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in _IGNORED_ERROS:
|
if not _ignore_error(e):
|
||||||
raise
|
raise
|
||||||
return False
|
return False
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -1343,7 +1352,7 @@ class Path(PurePath):
|
||||||
try:
|
try:
|
||||||
return S_ISDIR(self.stat().st_mode)
|
return S_ISDIR(self.stat().st_mode)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in _IGNORED_ERROS:
|
if not _ignore_error(e):
|
||||||
raise
|
raise
|
||||||
# Path doesn't exist or is a broken symlink
|
# Path doesn't exist or is a broken symlink
|
||||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||||
|
@ -1360,7 +1369,7 @@ class Path(PurePath):
|
||||||
try:
|
try:
|
||||||
return S_ISREG(self.stat().st_mode)
|
return S_ISREG(self.stat().st_mode)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in _IGNORED_ERROS:
|
if not _ignore_error(e):
|
||||||
raise
|
raise
|
||||||
# Path doesn't exist or is a broken symlink
|
# Path doesn't exist or is a broken symlink
|
||||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||||
|
@ -1397,7 +1406,7 @@ class Path(PurePath):
|
||||||
try:
|
try:
|
||||||
return S_ISLNK(self.lstat().st_mode)
|
return S_ISLNK(self.lstat().st_mode)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in _IGNORED_ERROS:
|
if not _ignore_error(e):
|
||||||
raise
|
raise
|
||||||
# Path doesn't exist
|
# Path doesn't exist
|
||||||
return False
|
return False
|
||||||
|
@ -1412,7 +1421,7 @@ class Path(PurePath):
|
||||||
try:
|
try:
|
||||||
return S_ISBLK(self.stat().st_mode)
|
return S_ISBLK(self.stat().st_mode)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in _IGNORED_ERROS:
|
if not _ignore_error(e):
|
||||||
raise
|
raise
|
||||||
# Path doesn't exist or is a broken symlink
|
# Path doesn't exist or is a broken symlink
|
||||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||||
|
@ -1428,7 +1437,7 @@ class Path(PurePath):
|
||||||
try:
|
try:
|
||||||
return S_ISCHR(self.stat().st_mode)
|
return S_ISCHR(self.stat().st_mode)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in _IGNORED_ERROS:
|
if not _ignore_error(e):
|
||||||
raise
|
raise
|
||||||
# Path doesn't exist or is a broken symlink
|
# Path doesn't exist or is a broken symlink
|
||||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||||
|
@ -1444,7 +1453,7 @@ class Path(PurePath):
|
||||||
try:
|
try:
|
||||||
return S_ISFIFO(self.stat().st_mode)
|
return S_ISFIFO(self.stat().st_mode)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in _IGNORED_ERROS:
|
if not _ignore_error(e):
|
||||||
raise
|
raise
|
||||||
# Path doesn't exist or is a broken symlink
|
# Path doesn't exist or is a broken symlink
|
||||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||||
|
@ -1460,7 +1469,7 @@ class Path(PurePath):
|
||||||
try:
|
try:
|
||||||
return S_ISSOCK(self.stat().st_mode)
|
return S_ISSOCK(self.stat().st_mode)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in _IGNORED_ERROS:
|
if not _ignore_error(e):
|
||||||
raise
|
raise
|
||||||
# Path doesn't exist or is a broken symlink
|
# Path doesn't exist or is a broken symlink
|
||||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
``pathlib`` no longer raises when checking file and directory existence on
|
||||||
|
drives that are not ready
|
Loading…
Add table
Add a link
Reference in a new issue