[issue33898] pathlib issues with Windows device paths

Eryk Sun report at bugs.python.org
Mon Jun 18 18:40:30 EDT 2018


New submission from Eryk Sun <eryksun at gmail.com>:

For \\?\ extended device paths, pathlib removes the trailing slash for the root directory if the device isn't UNC or a logical (A-Z) drive.

Correct:

    >>> str(Path('//?/UNC/'))
    '\\\\?\\UNC\\'

    >>> str(Path('//?/Z:/'))
    '\\\\?\\Z:\\'

Incorrect:

    >>> str(Path('//?/BootPartition/'))
    '\\\\?\\BootPartition'

    >>> str(Path('//?/Volume{}/'))
    '\\\\?\\Volume{}'

    >>> str(Path('//?/Global/Z:/'))
    '\\\\?\\Global\\Z:'

It keeps the trailing slash for some \\.\ paths, but not all.

Correct:

    >>> str(Path('//./BootPartition/'))
    '\\\\.\\BootPartition\\'

Incorrect:

    >>> str(Path('//./Global/Z:/'))
    '\\\\.\\Global\\Z:'

It adds a root directory to \\.\ device paths where none was specified. 

Incorrect:

    >>> str(Path('//./nul'))
    '\\\\.\\nul\\'

    >>> str(Path('//./PhysicalDrive0'))
    '\\\\.\\PhysicalDrive0\\'

    >>> str(Path('//./C:'))
    '\\\\.\\C:\\'

"\\\\.\\C:" refers to the volume device, whereas "\\\\.\\C:\\" is the root directory in the file system.

pathlib should parse \\?\ and \\.\ device paths the same way with respect to the drive and root. The difference in practice is only how Windows does (\\.\) or does not (\\?\) canonicalize the path. 

Additionally, pathlib fails to identify the drive correctly in these cases.

Incorrect:

    >>> Path('//?/Global/Z:/').drive
    '\\\\?\\'

    >>> Path('//?/BootPartition/Temp').drive
    '\\\\?\\'

Except for "UNC" and "Global" paths, the drive should be the first component after the local-device prefix. The "UNC" device also includes subsequent server and share components, if any. For the reserved "Global" symlink, it should look to the next component. For example, r'\\?\Global\UNC\server\share' is a drive. 

There's also the "GlobalRoot" symlink (or "Global\\GlobalRoot" to be pedantic), but that can't be handled generically.

----------
components: Library (Lib), Windows
messages: 319921
nosy: eryksun, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
stage: test needed
status: open
title: pathlib issues with Windows device paths
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33898>
_______________________________________


More information about the Python-bugs-list mailing list