[issue37609] support "UNC" device paths in ntpath.splitdrive
Eryk Sun
report at bugs.python.org
Wed Jul 17 07:26:34 EDT 2019
New submission from Eryk Sun <eryksun at gmail.com>:
Windows Python includes UNC shares such as "//server/spam" in its definition of a drive. This is natural because Windows supports setting a UNC path as the working directory and handles the share component as the working drive when resolving rooted paths such as "/eggs". For the sake of generality when working with \\?\ extended paths, Python should expand its definition of a UNC drive to include "UNC" device paths.
A practical example is calling glob.glob with a "//?/UNC" device path.
>>> import os, sys, glob
>>> sys.addaudithook(lambda s,a: print('#', a[0]) if s == 'glob.glob' else None)
regular UNC path:
>>> glob.glob('//localhost/C$/Sys*')
# //localhost/C$/Sys*
['//localhost/C$/System Volume Information']
"UNC" device path:
>>> glob.glob('//?/UNC/localhost/C$/Sys*')
# //?/UNC/localhost/C$/Sys*
# //?/UNC/localhost/C$
# //?/UNC/localhost
# //?/UNC/
[]
Since the magic character "?" is in the path (IMO, the drive should be excluded from this check, but that's a separate issue), the internal function glob._iglob calls itself recursively until it reaches the base case of dirname == pathname, where dirname is from os.path.split(pathname). The problem here is that ntpath.split doesn't stop at the proper base case of "//?/UNC/localhost/C$". This is due to ntpath.splitdrive. For example:
>>> os.path.splitdrive('//?/UNC/localhost/C$/Sys*')
('//?/UNC', '/localhost/C$/Sys*')
>>> os.path.splitdrive('//./UNC/localhost/C$/Sys*')
('//./UNC', '/localhost/C$/Sys*')
The results should be "//?/UNC/localhost/C$" and "//./UNC/localhost/C$".
In other cases, returning a device as the drive is fine, if not exactly meaningful (e.g. "//./NUL"). I don't think this needs to change.
----------
components: Library (Lib), Windows
messages: 348055
nosy: eryksun, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
stage: needs patch
status: open
title: support "UNC" device paths in ntpath.splitdrive
type: behavior
versions: Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37609>
_______________________________________
More information about the Python-bugs-list
mailing list