classification
Title: os.makedirs('/', exist_ok=True) fails on Darwin
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jeffrey.Kintscher, mew, ned.deily, r.david.murray
Priority: normal Keywords:

Created on 2015-05-18 17:23 by mew, last changed 2019-07-17 10:24 by SilentGhost. This issue is now closed.

Messages (6)
msg243501 - (view) Author: Matthew Wedgwood (mew) Date: 2015-05-18 17:23
On Darwin, os.mkdir('/') raises IsADirectory. On Linux, the same call raises FileExistsError. The implementation for os.makedirs() in Python 3.2+ checks only for the latter when evaluating the exists_ok parameter. This causes os.makedirs('/', exist_ok=True) to fail on Darwin but succeed on Linux.
msg243506 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-18 17:31
This should (in theory at least) be something we test in our test suite, so I'm surprised by this result.  If you run the test suite do you get any failures?
msg243512 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-05-18 18:16
This appears to be a BSD-ism: I get the same result on FreeBSD 10 as with OS X 10.10.  For whatever reason, mkdir('/') returns IsADirectoryError while mkdir('/other/existing/directory') returns FileExistsError.
msg243520 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-18 19:03
Ah!  That's why our tests don't catch it.

Is it limited to '/', or is it any (mounted) mount point?
msg243527 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-05-18 19:42
It doesn't seem to be true for other mount points; the ones I tried raise FileExistsError.  I suppose one could dig into the OS sources.  I see that none of the FreeBSD or OS X mkdir man pages nor the POSIX 2013 spec document EISDIR as an expected error from mkdir(2) so one could argue it's an implementation bug.  It is a somewhat unusual case, though, as I doubt you would ever run into a situation where you really needed to create '/' from a process :=)  Still ...
msg348046 - (view) Author: Jeffrey Kintscher (Jeffrey.Kintscher) * Date: 2019-07-16 23:50
This issue appears to have been fixed:

Python 3.7.3 (default, May  1 2019, 00:00:47) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.makedirs('/', exist_ok=True)
>>>
History
Date User Action Args
2019-07-17 10:24:06SilentGhostsetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2019-07-16 23:50:07Jeffrey.Kintschersetmessages: + msg348046
2019-06-06 00:06:25Jeffrey.Kintschersetnosy: + Jeffrey.Kintscher
2015-05-18 19:42:26ned.deilysetmessages: + msg243527
2015-05-18 19:03:04r.david.murraysetmessages: + msg243520
2015-05-18 18:16:27ned.deilysetversions: + Python 3.5
nosy: + ned.deily

messages: + msg243512

stage: needs patch
2015-05-18 17:31:13r.david.murraysetnosy: + r.david.murray
messages: + msg243506
2015-05-18 17:23:41mewcreate