You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
os.makedirs fails on long-path UNC-paths if it is the first sub-folder #85871
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:
assignee=Noneclosed_at=Nonecreated_at=<Date2020-09-03.19:28:37.918>labels= ['type-bug', '3.8', 'OS-windows']
title='os.makedirs fails on long-path UNC-paths if it is the first sub-folder'updated_at=<Date2020-09-03.22:01:32.759>user='https://github.com/Safihre'
It consistently fails on the first directory in a long-path UNC notation server-folder.
>>> os.makedirs(r"\\?\UNC\DiskStation\already_exists", exist_ok=True)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\safihre\AppData\Local\Programs\Python\Python38\lib\os.py", line 213, in makedirs
makedirs(head, exist_ok=exist_ok)
File "C:\Users\safihre\AppData\Local\Programs\Python\Python38\lib\os.py", line 213, in makedirs
makedirs(head, exist_ok=exist_ok)
File "C:\Users\safihre\AppData\Local\Programs\Python\Python38\lib\os.py", line 223, in makedirs
mkdir(name, mode)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '\\\\?\\UNC\\'
>>> os.makedirs(r"\\?\UNC\DiskStation\already_exists")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\safihre\AppData\Local\Programs\Python\Python38\lib\os.py", line 213, in makedirs
makedirs(head, exist_ok=exist_ok)
File "C:\Users\safihre\AppData\Local\Programs\Python\Python38\lib\os.py", line 213, in makedirs
makedirs(head, exist_ok=exist_ok)
File "C:\Users\safihre\AppData\Local\Programs\Python\Python38\lib\os.py", line 223, in makedirs
mkdir(name, mode)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '\\\\?\\UNC\\'
The second level directory is working correctly as expected:
>>> os.makedirs(r"\\?\UNC\DiskStation\already_exists\new")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\safihre\AppData\Local\Programs\Python\Python38\lib\os.py", line 223, in makedirs
mkdir(name, mode)
FileExistsError: [WinError 183] Cannot create a file when that file already exists: '\\\\?\\UNC\\DiskStation\\test_get2\\test2'
Inspecting the code, I think the problem is in the os.path.exists function that is called from within os.makedirs, the line in os.makedirs says:
if head and tail and not path.exists(head):
changed the title [-]os.makedirs fails long-path UNC-paths if it is the first sub-folder[/-][+]os.makedirs fails on long-path UNC-paths if it is the first sub-folder[/+]on Sep 3, 2020
changed the title [-]os.makedirs fails long-path UNC-paths if it is the first sub-folder[/-][+]os.makedirs fails on long-path UNC-paths if it is the first sub-folder[/+]on Sep 3, 2020
The result should be "//?/UNC/server/share". A path on the "UNC" device requires a share component, on which is mounted a local or remote filesystem directory. It's functionally part of the 'drive' path. Using just the root path or a server path on the "UNC" device is malformed in the context of a normal file API open. The former fails as ERROR_INVALID_NAME (123), and the latter fails as ERROR_BAD_PATHNAME (161).
The incorrect splitdrive result in turn makes ntpath.split misbehave:
@barneygale can you confirm if this is also resolved with your patch? The source of the problem is indicated by @eryksun to be in splitdrive. #85871 (comment)
Activity
Safihre commentedon Sep 3, 2020
It consistently fails on the first directory in a long-path UNC notation server-folder.
The second level directory is working correctly as expected:
>>> os.makedirs(r"\\?\UNC\DiskStation\already_exists\new") Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Users\safihre\AppData\Local\Programs\Python\Python38\lib\os.py", line 223, in makedirs mkdir(name, mode) FileExistsError: [WinError 183] Cannot create a file when that file already exists: '\\\\?\\UNC\\DiskStation\\test_get2\\test2'Inspecting the code, I think the problem is in the os.path.exists function that is called from within os.makedirs, the line in os.makedirs says:
if head and tail and not path.exists(head):
So it wrongly goes ahead and tries to create \\?\UNC\DiskStation
[-]os.makedirs fails long-path UNC-paths if it is the first sub-folder[/-][+]os.makedirs fails on long-path UNC-paths if it is the first sub-folder[/+][-]os.makedirs fails long-path UNC-paths if it is the first sub-folder[/-][+]os.makedirs fails on long-path UNC-paths if it is the first sub-folder[/+]eryksun commentedon Sep 3, 2020
This behavior is due to bpo-37609, i.e. ntpath.splitdrive fails for "UNC" device paths.
>>> ntpath.splitdrive('//?/UNC/server/share') ('//?/UNC', '/server/share')The result should be "//?/UNC/server/share". A path on the "UNC" device requires a share component, on which is mounted a local or remote filesystem directory. It's functionally part of the 'drive' path. Using just the root path or a server path on the "UNC" device is malformed in the context of a normal file API open. The former fails as ERROR_INVALID_NAME (123), and the latter fails as ERROR_BAD_PATHNAME (161).
The incorrect splitdrive result in turn makes ntpath.split misbehave:
>>> ntpath.split('//?/UNC/server/share') ('//?/UNC/server', 'share') >>> ntpath.split('//?/UNC/server') ('//?/UNC/', 'server')The correct result should be ('//?/UNC/server/share', '').
Safihre commentedon Jun 11, 2022
@barneygale can you confirm if this is also resolved with your patch? The source of the problem is indicated by @eryksun to be in
splitdrive.#85871 (comment)
picnixz commentedon Dec 3, 2024
@barneygale friendly ping for confirmation (otherwise, we can close this issue)