This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.split() and long UNC names
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, kaba2, kevin.chen, kushal.das, larry, mhammond, serhiy.storchaka, terry.reedy
Priority: normal Keywords: easy

Created on 2012-09-07 16:40 by kaba2, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (9)
msg169990 - (view) Author: Kalle Rutanen (kaba2) Date: 2012-09-07 16:40
On Windows, long-UNC paths are needed to inspect and modify paths with more than 260 characters. The os.path.split() function behaves incorrectly in the presence of a long-UNC prefix //?/ or \\?\. Consider iterating d = os.path.split(d)[0] with d = '//?/e:/python-test/dir'. Then the values of d are as follows:

'//?/e:/python-test/dir'
'//?/e:/python-test'
'//?/e:'
'//?'
'//'

The two last splits are the incorrect ones, where the splitting should end at '//?/e:'.

One consequence of this is that os.makedirs(d) crashes, because it attempts to run os.mkdir('//') at the bottom of its recursion. The same thing happens when replacing all / with \\ in the above.
msg169992 - (view) Author: Kalle Rutanen (kaba2) Date: 2012-09-07 16:50
By inspecting the code for os.path.split() in ntpath.py, one sees that the problem is actually in os.path.splitdrive(), which does not handle long-UNC paths.
msg169995 - (view) Author: Kalle Rutanen (kaba2) Date: 2012-09-07 17:06
It seems to me that this problem can be fixed by replacing splitdrive with splitunc at line 170 in ntpath.py.
msg172450 - (view) Author: Kushal Das (kushal.das) * (Python committer) Date: 2012-10-09 05:58
splitunc is deprecated since 3.1. It is also written in the code that "Paths containing drive letters never have an UNC part"
msg174486 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-02 00:06
This behavior reproduced only on 2.7.  See issue5799 which changed the behavior for 3.1.
msg175427 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-12 09:09
I propose to close this issue as "won't fix".  A long-UNC prefix support is a new feature and can't be applied to 2.7.  As workaround use splitunc() in Python prior to 3.1.
msg175465 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-11-12 19:30
I agree. Larry H.'s patch in #5799 was called an enhancement and is explicitly a replacement for splitunc. The latter was deprecated and may disappear in 3.4.
msg175468 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-11-12 20:00
ISTM that fixing this for 3.x (3? 4?) is worthwhile though.  Or did somebody already fix it in 3.x?
msg175469 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-11-12 20:11
Serhiy claims that the commit of Mark's version of your patch in #5799 fixed this in 3.1. Retesting in IDLE, 3.3, Win7:

>>> import os
>>> d = '//?/e:/python-test/dir'
>>> d = os.path.split(d)[0]
>>> d
'//?/e:/python-test'
>>> d = os.path.split(d)[0]
>>> d
'//?/e:/'
>>> d = os.path.split(d)[0]
>>> d
'//?/e:/'

So the splitting ends where Kalle agrees it should.
History
Date User Action Args
2022-04-11 14:57:35adminsetgithub: 60084
2012-11-12 20:11:44terry.reedysetmessages: + msg175469
2012-11-12 20:00:18larrysetmessages: + msg175468
2012-11-12 19:30:00terry.reedysetstatus: pending -> closed
resolution: wont fix
messages: + msg175465

stage: test needed -> resolved
2012-11-12 09:09:43serhiy.storchakasetstatus: open -> pending

messages: + msg175427
2012-11-02 00:06:21serhiy.storchakasetnosy: + mhammond, larry, serhiy.storchaka

messages: + msg174486
versions: - Python 3.2, Python 3.3
2012-11-01 23:35:37kevin.chensetnosy: + kevin.chen
2012-10-09 05:58:39kushal.dassetnosy: + kushal.das
messages: + msg172450
2012-09-15 06:02:18ezio.melottisetversions: + Python 3.2, Python 3.3
nosy: + ezio.melotti

keywords: + easy
type: crash -> behavior
stage: test needed
2012-09-14 17:45:18terry.reedysetnosy: + terry.reedy
2012-09-07 17:06:53kaba2setmessages: + msg169995
2012-09-07 16:50:50kaba2setmessages: + msg169992
2012-09-07 16:40:15kaba2create