Eryk Sun <eryk...@gmail.com> added the comment:

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

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45597>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to