Skip to content
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

bpo-38671: Make sure to return an absolute path in pathlib._WindowsFlavour.resolve() #17716

Open
wants to merge 1 commit into
base: master
from

Conversation

@uranusjr
Copy link
Contributor

uranusjr commented Dec 27, 2019

@uranusjr uranusjr force-pushed the uranusjr:path-resolve-nonstrict-win branch 2 times, most recently from 87e0e37 to 78953ba Dec 27, 2019
This guarentees we are returning an absolute path when the input `path`
is relative. Nothing would change if `path` is already absolute.
@uranusjr uranusjr force-pushed the uranusjr:path-resolve-nonstrict-win branch from 78953ba to 34c68f7 Dec 28, 2019
if previous_s == s:
return path
return os.path.join(s or os.getcwd(), *reversed(tail_parts))

This comment has been minimized.

Copy link
@eryksun

eryksun Dec 28, 2019

Contributor

At the beginning, I'd rather set s = path = os.path.abspath(path). Note that _getfinalpathname calls CreateFileW, which internally calls GetFullPathNameW on all paths except for ones that begin with exactly "\\?\" (backslash only). This means that ".." components in normalized paths are resolved naively, so it's fine to do the same via abspath. Calling abspath at the start also lets us resolve special DOS-device paths such as "C:\Temp\nul.txt" -> "\\.\nul".

This comment has been minimized.

Copy link
@uranusjr

uranusjr Dec 28, 2019

Author Contributor

By “at the start” do you mean line 205? One advantage of _getfinalpathname over abspath is that it canonicalize the case (e.g. python.EXE -> python.exe), which abspath can’t do. I think we need to keep that.

This comment has been minimized.

Copy link
@eryksun

eryksun Dec 28, 2019

Contributor

I meant line 194, i.e. replace s = str(path) with s = path = os.path.abspath(path). I wasn't proposing to replace _getfinalpathname. It is irreplaceable in this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.