-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-38671: Make sure to return an absolute path in pathlib._WindowsFlavour.resolve() #17716
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e503cd6
3f9d1b8
612b7f6
7cff82e
8f20c10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
|
||
|
||
if os.name == 'nt': | ||
from nt import _getfinalpathname | ||
from nt import _getfinalpathname, _getfullpathname | ||
else: | ||
_getfinalpathname = None | ||
|
||
|
@@ -189,26 +189,26 @@ def compile_pattern(self, pattern): | |
def resolve(self, path, strict=False): | ||
s = str(path) | ||
if not s: | ||
return path._accessor.getcwd() | ||
s = path._accessor.getcwd() | ||
if _getfinalpathname is None: | ||
return None # Means fallback on absolute | ||
if strict: | ||
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. Lines 189-191 make a bad assumption that the current working directory (CWD) is a final path. The CWD is an absolute path but not a final path. The assignment should be something like 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.
TIL. I like the |
||
return self._ext_to_normal(_getfinalpathname(s)) | ||
s = path = _getfullpathname(s) | ||
previous_s = None | ||
if _getfinalpathname is not None: | ||
if strict: | ||
return self._ext_to_normal(_getfinalpathname(s)) | ||
tail_parts = [] # End of the path after the first one not found | ||
while True: | ||
try: | ||
s = self._ext_to_normal(_getfinalpathname(s)) | ||
except FileNotFoundError: | ||
previous_s = s | ||
s, tail = os.path.split(s) | ||
tail_parts.append(tail) | ||
if previous_s == s: | ||
# Root reached, fallback to _getfullpathname() | ||
return path | ||
else: | ||
tail_parts = [] # End of the path after the first one not found | ||
while True: | ||
try: | ||
s = self._ext_to_normal(_getfinalpathname(s)) | ||
except FileNotFoundError: | ||
previous_s = s | ||
s, tail = os.path.split(s) | ||
tail_parts.append(tail) | ||
if previous_s == s: | ||
return path | ||
else: | ||
return os.path.join(s, *reversed(tail_parts)) | ||
# Means fallback on absolute | ||
return None | ||
return os.path.join(s, *reversed(tail_parts)) | ||
|
||
def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix): | ||
prefix = '' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Ensure pathlib.Path.resolve(strict=False) returns an absolute path on | ||
Windows when the path is relative and does not exist. |
Uh oh!
There was an error while loading. Please reload this page.