Message390476
> The 3.8 backport is much more complicated, as we don't have access to > the PathSkipRoot function there. So we can't use the native function. I guess you missed the comment that I left on the PR a few days ago. The 3.8 backport can use the older PathSkipRootW() in shlwapi.dll [1]. It works similarly, except it doesn't support a drive relative root such as "C:spam" -> ("C:", "spam"), but it's easy enough to handle that case in C. Also, it's documented that it's limited to MAX_PATH, but it works fine with long paths in Windows 10, even if the process does not have long-path support enabled. Anyway, just limit the copy to the first `MAX_PATH - 1` characters. Practically speaking, no root is anywhere near that long. It would require a ridiculously long device name in a "\\.\" device path. Examples: import ctypes shlwapi = ctypes.WinDLL('shlwapi') shlwapi.PathSkipRootW.restype = ctypes.c_wchar_p path = (ctypes.c_wchar * 1000)() It returns NULL if there's no root: >>> path.value = r'spam' >>> shlwapi.PathSkipRootW(path) is None True Drive-relative paths aren't supported the same as they are in PathCchSkipRoot(): >>> path.value = r'C:spam' >>> shlwapi.PathSkipRootW(path) is None True Otherwise it seems to support the same range of paths as PathCchSkipRoot(): >>> path.value = r'\spam' >>> shlwapi.PathSkipRootW(path) 'spam' >>> path.value = r'C:\spam' >>> shlwapi.PathSkipRootW(path) 'spam' >>> path.value = r'\\server\share\spam' >>> shlwapi.PathSkipRootW(path) 'spam' >>> path.value = r'\\?\C:\spam' >>> shlwapi.PathSkipRootW(path) 'spam' >>> path.value = r'\\?\UNC\server\share\spam' >>> shlwapi.PathSkipRootW(path) 'spam' >>> path.value = r'\\?\Volume{12345678-1234-1234-1234-123456789ABC}\spam' >>> shlwapi.PathSkipRootW(path) 'spam' >>> path.value = r'\\.\PIPE\spam' >>> shlwapi.PathSkipRootW(path) 'spam' --- [1] https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathskiprootw | |
| Date | User | Action | Args | | 2021-04-07 21:13:43 | eryksun | set | recipients: + eryksun, brett.cannon, paul.moore, tim.golden, zach.ware, steve.dower, smunday | | 2021-04-07 21:13:43 | eryksun | set | messageid: <1617830023.8.0.245875153564.issue43105@roundup.psfhosted.org> | | 2021-04-07 21:13:43 | eryksun | link | issue43105 messages | | 2021-04-07 21:13:43 | eryksun | create | | |