Skip to content

Commit 4114be9

Browse files
committed
Raise RuntimeError in Path.resolve() if realpath() raises ERROR_CANT_RESOLVE_FILENAME
1 parent fe69688 commit 4114be9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Lib/pathlib.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@
2929
# Internals
3030
#
3131

32+
_WINERROR_NOT_READY = 21 # drive exists but is not accessible
33+
_WINERROR_INVALID_NAME = 123 # fix for bpo-35306
34+
_WINERROR_CANT_RESOLVE_FILENAME = 1921 # broken symlink pointing to itself
35+
3236
# EBADF - guard against macOS `stat` throwing EBADF
3337
_IGNORED_ERROS = (ENOENT, ENOTDIR, EBADF, ELOOP)
3438

3539
_IGNORED_WINERRORS = (
36-
21, # ERROR_NOT_READY - drive exists but is not accessible
37-
123, # ERROR_INVALID_NAME - fix for bpo-35306
38-
1921, # ERROR_CANT_RESOLVE_FILENAME - fix for broken symlink pointing to itself
39-
)
40+
_WINERROR_NOT_READY,
41+
_WINERROR_INVALID_NAME,
42+
_WINERROR_CANT_RESOLVE_FILENAME)
4043

4144
def _ignore_error(exception):
4245
return (getattr(exception, 'errno', None) in _IGNORED_ERROS or
@@ -1061,7 +1064,8 @@ def resolve(self, strict=False):
10611064
try:
10621065
p = self._accessor.realpath(self, strict=strict)
10631066
except OSError as ex:
1064-
if ex.errno == ELOOP:
1067+
winerr = getattr(ex, 'winerror', 0)
1068+
if ex.errno == ELOOP or winerr == _WINERROR_CANT_RESOLVE_FILENAME:
10651069
raise RuntimeError("Symlink loop from %r", ex.filename)
10661070
raise
10671071
return self._from_parts((p,))

0 commit comments

Comments
 (0)