-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
os.path.realpath returns invalid path for junction pointing to letter-less volume #89760
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
Comments
If a path contains a junction pointing to a dir on a letter-less drive then This path, of course, doesn't work correctly. Actually, it looks relative. Original issue: pypa/pip#10597 |
This is from checking whether the \\?\ prefix can be stripped. The _getfinalpathname() call that it makes fails with the initial winerror (ERROR_PATH_NOT_FOUND), since nt._getfinalpathname() still lacks support for volume GUID paths. In this case, it assumes the path doesn't exist and removes the prefix. This check should be skipped for all prefixed paths if they aren't drives or UNC shares. For example, if colon_sep (i.e. ":\\") is defined: # The path returned by _getfinalpathname will always start with \\?\ -
# strip off that prefix unless it was already provided on the original
# path.
if not had_prefix and path.startswith(prefix):
# For UNC paths, the prefix will be \\?\UNC\
if path.startswith(unc_prefix):
spath = new_unc_prefix + path[len(unc_prefix):]
# For drive paths, the root is of the form \\?\X:\
elif path.startswith(colon_sep, len(prefix) + 1):
spath = path[len(prefix):]
# For all others, the prefix must be retained.
else:
spath = None
if spath is not None:
# Ensure that the non-prefixed path resolves to the same path
try:
if _getfinalpathname(spath) == path:
path = spath
except OSError as ex:
# If the path does not exist and originally did not exist, then
# strip the prefix anyway.
if ex.winerror == initial_winerror:
path = spath
return path |
@eryksun, are you proposing a change to discuss, or…? |
Yes, the suggested change in
|
Why not open a PR?
I meant, the term "drive path" is not wide-accepted.
And what results would I haven't tested, but IIUC, these flags aren't fallbacks. They choose which variant should be returned when there are several possibilities (with drive letter or with volume GUID). But if there is no letter, |
Note that reproducing the issue requires the error after stripping the "\\?\" prefix to match Also, there's no misbehavior if the path of the junction is registered with the mount point manager as the canonical DOS path of the volume, e.g. a junction created by "mountvol.exe" or WinAPI
Personally, I prefer to discuss ideas in the issue itself. It leaves a more accessible record. I've learned a lot from reading old issues. You're welcome to create a PR if you're eager to resolve this issue. I'll try to help with code review and testing.
If a volume has no canonical DOS mount point, then requesting But, as I said, for this issue it's better to modify
How about clarifying the comments as "For UNC drives, the path starts with \\?\UNC\", and "For drive-letter drives, the path starts with \\?\<drive letter>:\"? |
I see. My mistake.
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: