-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pathlib] issues with Windows device paths #78079
Comments
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. |
Eryk - I've got the PR ready as far as I'm concerned. Have you had a look to see if you're happy with its logic for these cases? |
I think this is the issue that requires The current PR doesn't seem to be easily resolvable, but is probably well out of date anyway because of other work that's been done in pathlib and ntpath. The existing test suite and the examples Eryk posted above are probably the best way to figure out the right semantics. |
Based on Eryk's test cases, >>> ntpath.splitroot('//./Global/Z:/')
('//./Global', '/', 'Z:/')
>>> ntpath.splitroot('//?/Global/Z:/')
('//?/Global', '/', 'Z:/') I believe that all the other failing test cases can be put down to pathlib erroneously adding roots to paths like |
Yeah, this is what I expected with "deliberate about the meaning of ... leading slash in the rest of the path". I know we've encountered these consistency issues before, but I don't know whether they were all resolved. |
We no longer add a root to device paths such as `//./PhysicalDrive0`, `//?/BootPartition` and `//./c:` while normalizing. We also avoid adding a root to incomplete UNC share paths, like `//`, `//a` and `//a/`.
We no longer add a root to device paths such as `//./PhysicalDrive0`, `//?/BootPartition` and `//./c:` while normalizing. We also avoid adding a root to incomplete UNC share paths, like `//`, `//a` and `//a/`.
We no longer add a root to device paths such as `//./PhysicalDrive0`, `//?/BootPartition` and `//./c:` while normalizing. We also avoid adding a root to incomplete UNC share paths, like `//`, `//a` and `//a/`.
I've opened a PR that fixes all of Eryk's test cases except |
This is done because `pathlib.Path` automatically adds a trailing backslash to Windows paths of the shape `\\.\PhysicalDriveN`. Trying to open such a path including the trailing backslash raises `PermissionError`. This issue is tracked at python/cpython#78079.
We no longer add a root to device paths such as `//./PhysicalDrive0`, `//?/BootPartition` and `//./c:` while normalizing. We also avoid adding a root to incomplete UNC share paths, like `//`, `//a` and `//a/`. Co-authored-by: Eryk Sun <[email protected]>
Hey @eryksun, do you think we should leave this issue open to cover the remaining "Global" and "GLOBALROOT" issues? The problem there lies mostly in |
* main: Remove `expert-*` from `project-updater` GH workflow (python#103579) pythongh-103583: Add codecs and maps to _codecs_* module state (python#103540) pythongh-48330: address review comments to PR-12271 (python#103209) pythongh-103527: Add multibytecodec.h as make dep for _codecs_* (python#103567) pythongh-103553: Improve `test_inspect`: add more assertions, remove unused (python#103554) pythonGH-103517: Improve tests for `pathlib.Path.walk()` (pythonGH-103518) pythongh-102114: Make dis print more concise tracebacks for syntax errors in str inputs (python#102115) pythonGH-78079: Fix UNC device path root normalization in pathlib (pythonGH-102003) pythongh-101517: Add regression test for a lineno bug in try/except* impacting pdb (python#103547) pythongh-103527: Add make deps for _codecs_* and _multibytecodec (python#103528) pythongh-103532: Fix reST syntax in NEWS entry (pythonGH-103544) pythongh-103532: Add NEWS entry (python#103542)
* superopt: update generated cases with new comment review comments Remove `expert-*` from `project-updater` GH workflow (python#103579) pythongh-103583: Add codecs and maps to _codecs_* module state (python#103540) pythongh-48330: address review comments to PR-12271 (python#103209) pythongh-103527: Add multibytecodec.h as make dep for _codecs_* (python#103567) pythongh-103553: Improve `test_inspect`: add more assertions, remove unused (python#103554) pythonGH-103517: Improve tests for `pathlib.Path.walk()` (pythonGH-103518) pythongh-102114: Make dis print more concise tracebacks for syntax errors in str inputs (python#102115) pythonGH-78079: Fix UNC device path root normalization in pathlib (pythonGH-102003) pythongh-101517: Add regression test for a lineno bug in try/except* impacting pdb (python#103547) pythongh-103527: Add make deps for _codecs_* and _multibytecodec (python#103528) pythongh-103532: Fix reST syntax in NEWS entry (pythonGH-103544) pythongh-103532: Add NEWS entry (python#103542)
I vote for a new issue (with a more descriptive title), and would also say it's not a high priority. If you can describe it well enough, might even be able to justify tagging it "easy" and offer it up for someone at sprints. |
Logged here: I don't understand the rules for "Global" and "GLOBALROOT" so it's not very well described :) Resolving this issue! Thanks all. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: