bpo-37609 - Support "UNC" and "GLOBAL" junctions in ntpath.splitdrive()
. by barneygale · Pull Request #31702 · python/cpython (original) (raw)
Thank you for picking this up, but, fair warning, it's going to need more work. If you're up for that, great. I'd love to get your opinions on what needs to be done.
Steve Dower introduced the idea of leveraging PathCchSkipRoot()
in Windows, and I like that idea, despite some reservations on my part. So I think splitdrive()
should try to conform with PathCchSkipRoot()
. As such, repetition of separators between the domain and junctions (e.g. UNC server and share) should be parsed as empty values for those components. Similar behavior would be extended to "\\?\UNC" paths.
At the time I wrote this, I was thinking to support whatever paths work in practice, but on closer scrutiny even GetFullPathNameW()
handles the initial slashes for the server and share components without normalizing repeated slashes. For example:
>>> n = GetFullPathNameW('//server//file', len(buf), buf, byref(filepart))
>>> print(buf.value)
\\server\file
>>> print(filepart.value)
file
>>> n = GetFullPathNameW('////file', len(buf), buf, byref(filepart))
>>> print(buf.value)
\\\file
>>> print(filepart.value)
file
For normal UNC filepaths, if os.chdir()
handles the path as a UNC path instead of as a rooted path on the current drive, then splitdrive()
should split out the 'drive' component, even if it's malformed (e.g. empty server or share component). Extend this behavior to "\\?\UNC" paths, as PathCchSkipRoot()
does, even though they're not valid for the current working directory.