Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.2k
[3.9] bpo-43757: Make pathlib use os.path.realpath() to resolve symlinks in a path (GH-25264)#135035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
[3.9] bpo-43757: Make pathlib use os.path.realpath() to resolve symlinks in a path (GH-25264)#135035
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -14,15 +14,6 @@ | ||
supports_symlinks = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This is left for backward compatibility in 3.9, but it's always True because the only way for it to get False is a pre-Vista version of Windows. Python 3.9 only supports Windows 8.1+. | ||
__all__ = [ | ||
@@ -34,14 +25,17 @@ | ||
# Internals | ||
# | ||
_WINERROR_NOT_READY = 21 # drive exists but is not accessible | ||
_WINERROR_INVALID_NAME = 123 # fix for bpo-35306 | ||
_WINERROR_CANT_RESOLVE_FILENAME = 1921 # broken symlink pointing to itself | ||
# EBADF - guard against macOS `stat` throwing EBADF | ||
_IGNORED_ERROS = (ENOENT, ENOTDIR, EBADF, ELOOP) | ||
_IGNORED_WINERRORS = ( | ||
_WINERROR_NOT_READY, | ||
_WINERROR_INVALID_NAME, | ||
_WINERROR_CANT_RESOLVE_FILENAME) | ||
def _ignore_error(exception): | ||
return (getattr(exception, 'errno', None) in _IGNORED_ERROS or | ||
@@ -200,30 +194,6 @@ def casefold_parts(self, parts): | ||
def compile_pattern(self, pattern): | ||
return re.compile(fnmatch.translate(pattern), re.IGNORECASE).fullmatch | ||
def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix): | ||
prefix = '' | ||
if s.startswith(ext_prefix): | ||
@@ -234,10 +204,6 @@ def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix): | ||
s = '\\' + s[3:] | ||
return prefix, s | ||
def is_reserved(self, parts): | ||
# NOTE: the rules for reserved names seem somewhat complicated | ||
# (e.g. r"..\NUL" is reserved but not r"foo\NUL" if "foo" does not | ||
@@ -324,54 +290,6 @@ def casefold_parts(self, parts): | ||
def compile_pattern(self, pattern): | ||
return re.compile(fnmatch.translate(pattern)).fullmatch | ||
def is_reserved(self, parts): | ||
return False | ||
@@ -443,17 +361,11 @@ def link_to(self, target): | ||
replace = os.replace | ||
if hasattr(os, "symlink"): | ||
symlink = os.symlink | ||
else: | ||
def symlink(self, src, dst, target_is_directory=False): | ||
raise NotImplementedError("os.symlink() not available on this system") | ||
utime = os.utime | ||
@@ -475,6 +387,12 @@ def group(self, path): | ||
except ImportError: | ||
raise NotImplementedError("Path.group() is unsupported on this system") | ||
getcwd = os.getcwd | ||
expanduser = staticmethod(os.path.expanduser) | ||
realpath = staticmethod(os.path.realpath) | ||
_normal_accessor = _NormalAccessor() | ||
@@ -1212,17 +1130,27 @@ def resolve(self, strict=False): | ||
normalizing it (for example turning slashes into backslashes under | ||
Windows). | ||
""" | ||
def check_eloop(e): | ||
winerror = getattr(e, 'winerror', 0) | ||
if e.errno == ELOOP or winerror == _WINERROR_CANT_RESOLVE_FILENAME: | ||
raise RuntimeError("Symlink loop from %r" % e.filename) | ||
try: | ||
s = self._accessor.realpath(self, strict=strict) | ||
except OSError as e: | ||
check_eloop(e) | ||
raise | ||
p = self._from_parts((s,)) | ||
# In non-strict mode, realpath() doesn't raise on symlink loops. | ||
# Ensure we get an exception by calling stat() | ||
if not strict: | ||
try: | ||
p.stat() | ||
except OSError as e: | ||
check_eloop(e) | ||
return p | ||
def stat(self): | ||
""" | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.