Skip to content

ntpath.realpath() should use GetFinalPathNameByHandle() #58302

Closed

Description

@vstinner
BPO 14094
Nosy @pfmoore, @amauryfa, @pitrou, @vstinner, @tjguk, @briancurtin, @akheron, @zware, @eryksun, @zooba, @vladima
PRs
  • bpo-14094: Use _getfinalpathname to implement realpath #11248
  • 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 = None
    closed_at = <Date 2019-09-11.13:13:11.798>
    created_at = <Date 2012-02-22.23:47:49.504>
    labels = ['3.8', 'type-feature', 'library', 'OS-windows']
    title = 'ntpath.realpath() should use GetFinalPathNameByHandle()'
    updated_at = <Date 2019-09-11.13:13:11.797>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2019-09-11.13:13:11.797>
    actor = 'steve.dower'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-09-11.13:13:11.798>
    closer = 'steve.dower'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2012-02-22.23:47:49.504>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 14094
    keywords = ['patch']
    message_count = 10.0
    messages = ['154018', '222954', '297133', '297139', '297188', '332094', '332152', '335040', '335042', '351857']
    nosy_count = 11.0
    nosy_names = ['paul.moore', 'amaury.forgeotdarc', 'pitrou', 'vstinner', 'tim.golden', 'brian.curtin', 'petri.lehtinen', 'zach.ware', 'eryksun', 'steve.dower', 'v2m']
    pr_nums = ['11248']
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue14094'
    versions = ['Python 3.8']

    Activity

    1. vstinner commented on Feb 22, 2012

      @vstinner
      MemberAuthor

      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 bpo-9333 (issue which added os.symlink() on Windows).

    2. added
      stdlib
      on Feb 22, 2012
    3. BreamoreBoy commented on Jul 13, 2014

      BreamoreBoymannequin
      Mannequin

      I'm assuming that this should be treated as an enhancement request.

    4. added
      type-feature
      on Jul 13, 2014
    5. vstinner commented on Jun 28, 2017

      @vstinner
      MemberAuthor

      Python 3 now uses GetFinalPathNameByHandle()!

    6. eryksun commented on Jun 28, 2017

      @eryksun
      Contributor

      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.

    7. changed the title [-]nt.realpath() should use GetFinalPathNameByHandle() when available[/-] [+]ntpath.realpath() should use GetFinalPathNameByHandle()[/+] on Jun 28, 2017
    8. vstinner commented on Jun 28, 2017

      @vstinner
      MemberAuthor

      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?

    9. vstinner commented on Dec 18, 2018

      @vstinner
      MemberAuthor

      Any update on this issue?

    10. added
      3.8 (EOL)
      and removed
      3.7 (EOL)
      on Dec 18, 2018
    11. vladima commented on Dec 19, 2018

      vladimamannequin
      Mannequin

      I can give it a try.

    12. eryksun commented on Feb 7, 2019

      @eryksun
      Contributor

      Ping on PR 11248. It would be nice to get this into 3.8.

    13. zooba commented on Feb 7, 2019

      @zooba
      Member

      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.

    14. zooba commented on Sep 11, 2019

      @zooba
      Member

      As of 3.8, it (sort of) does.

    15. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)OS-windowsstdlibtype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions