classification
Title: ntpath.realpath() should use GetFinalPathNameByHandle()
Type: enhancement Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.8
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, brian.curtin, eryksun, paul.moore, petri.lehtinen, pitrou, steve.dower, tim.golden, v2m, vstinner, zach.ware
Priority: normal Keywords: patch

Created on 2012-02-22 23:47 by vstinner, last changed 2019-09-11 13:13 by steve.dower. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11248 closed v2m, 2018-12-20 07:34
Messages (10)
msg154018 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-02-22 23:47
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);

    if(!buf_size)
        return win32_error_object("GetFinalPathNameByHandle", po);

    target_path = (wchar_t *)malloc((buf_size+1)*sizeof(wchar_t));
    if(!target_path)
        return PyErr_NoMemory();

    result_length = Py_GetFinalPathNameByHandleW(hFile, target_path,
                                                 buf_size, VOLUME_NAME_DOS);

See also issue #9333 (issue which added os.symlink() on Windows).
msg222954 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-13 16:42
I'm assuming that this should be treated as an enhancement request.
msg297133 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-28 01:44
Python 3 now uses GetFinalPathNameByHandle()!
msg297139 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2017-06-28 02:25
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.
msg297188 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-28 14:33
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?
msg332094 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-18 22:38
Any update on this issue?
msg332152 - (view) Author: Vladimir Matveev (v2m) * Date: 2018-12-19 17:03
I can give it a try.
msg335040 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-02-07 20:33
Ping on PR 11248. It would be nice to get this into 3.8.
msg335042 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-02-07 22:08
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.
msg351857 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-09-11 13:13
As of 3.8, it (sort of) does.
History
Date User Action Args
2019-09-11 13:13:11steve.dowersetstatus: open -> closed
resolution: out of date
messages: + msg351857

stage: patch review -> resolved
2019-02-26 02:32:10eryksunlinkissue36112 superseder
2019-02-07 22:08:46steve.dowersetmessages: + msg335042
2019-02-07 20:33:37eryksunsetmessages: + msg335040
2019-02-07 20:20:32eryksunsetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
components: + Windows
2019-02-07 20:19:53eryksunsetcomponents: - Windows
2018-12-20 07:34:22v2msetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request10488
2018-12-19 17:03:44v2msetnosy: + v2m
messages: + msg332152
2018-12-18 22:38:14vstinnersetmessages: + msg332094
versions: + Python 3.8, - Python 3.7
2017-06-28 14:33:45vstinnersetmessages: + msg297188
2017-06-28 14:13:19BreamoreBoysetnosy: - BreamoreBoy
2017-06-28 02:25:56eryksunsetstatus: closed -> open


title: nt.realpath() should use GetFinalPathNameByHandle() when available -> ntpath.realpath() should use GetFinalPathNameByHandle()
nosy: + eryksun
versions: + Python 3.7, - Python 3.5
messages: + msg297139
resolution: fixed -> (no value)
stage: resolved -> needs patch
2017-06-28 01:44:50vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg297133

stage: resolved
2014-07-13 16:42:31BreamoreBoysetversions: + Python 3.5, - Python 3.3
nosy: + BreamoreBoy

messages: + msg222954

type: enhancement
2013-01-03 01:15:21vstinnersetcomponents: + Windows
2012-02-27 09:31:35petri.lehtinensetnosy: + petri.lehtinen
2012-02-22 23:48:11vstinnersetnosy: + amaury.forgeotdarc
2012-02-22 23:47:49vstinnercreate