You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ntpath.realpath() should use GetFinalPathNameByHandle() #58302
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:
assignee=Noneclosed_at=<Date2019-09-11.13:13:11.798>created_at=<Date2012-02-22.23:47:49.504>labels= ['3.8', 'type-feature', 'library', 'OS-windows']
title='ntpath.realpath() should use GetFinalPathNameByHandle()'updated_at=<Date2019-09-11.13:13:11.797>user='https://github.com/vstinner'
nt.realpath() should use GetFinalPathNameByHandleW() when available, instead of GetFullPathNameW(), to resolve symlinks.
By the way, it's strange that Py_GetFinalPathNameByHandleW() is called with VOLUME_NAME_NT to get the buffer size, and then with VOLUME_NAME_DOS. Is it a bug?
/* We have a good handle to the target, use it to determine the
target path name. */
buf_size = Py_GetFinalPathNameByHandleW(hFile, 0, 0, VOLUME_NAME_NT);
I assume by nt.realpath we're talking about ntpath.realpath. In that case nothing was done to fix this. It's still an alias for ntpath.abspath, which calls GetFullPathNameW.
changed the title [-]nt.realpath() should use GetFinalPathNameByHandle() when available[/-][+]ntpath.realpath() should use GetFinalPathNameByHandle()[/+]on Jun 28, 2017
Oh, only os.stat() was patched to use GetFinalPathNameByHandle()? It seems like most of the code was already written, so it shouldn't be hard to add a nt.GetFinalPathName() function using the win32_xstat_impl() code (and get_target_path()), to implement a real ntpath.realpath(), no?
Activity
vstinner commentedon Feb 22, 2012
nt.realpath() should use GetFinalPathNameByHandleW() when available, instead of GetFullPathNameW(), to resolve symlinks.
By the way, it's strange that Py_GetFinalPathNameByHandleW() is called with VOLUME_NAME_NT to get the buffer size, and then with VOLUME_NAME_DOS. Is it a bug?
See also issue bpo-9333 (issue which added os.symlink() on Windows).
BreamoreBoy commentedon Jul 13, 2014
I'm assuming that this should be treated as an enhancement request.
vstinner commentedon Jun 28, 2017
Python 3 now uses GetFinalPathNameByHandle()!
eryksun commentedon Jun 28, 2017
I assume by nt.realpath we're talking about ntpath.realpath. In that case nothing was done to fix this. It's still an alias for ntpath.abspath, which calls GetFullPathNameW.
[-]nt.realpath() should use GetFinalPathNameByHandle() when available[/-][+]ntpath.realpath() should use GetFinalPathNameByHandle()[/+]vstinner commentedon Jun 28, 2017
Oh, only os.stat() was patched to use GetFinalPathNameByHandle()? It seems like most of the code was already written, so it shouldn't be hard to add a nt.GetFinalPathName() function using the win32_xstat_impl() code (and get_target_path()), to implement a real ntpath.realpath(), no?
@eryk: Are you interested to work on a patch?
vstinner commentedon Dec 18, 2018
Any update on this issue?
vladima commentedon Dec 19, 2018
I can give it a try.
eryksun commentedon Feb 7, 2019
Ping on PR 11248. It would be nice to get this into 3.8.
zooba commentedon Feb 7, 2019
Posted a review. I suggest a few changes for the sake of tidying up, but I agree that I'd like to see more tests added.
zooba commentedon Sep 11, 2019
As of 3.8, it (sort of) does.