Issue 24231: os.makedirs('/', exist_ok=True) fails on Darwin (original) (raw)

Created on 2015-05-18 17:23 by mew, last changed 2022-04-11 14:58 by admin. 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
2022-04-11 14:58:17 admin set github: 68419
2019-07-17 10:24:06 SilentGhost set status: open -> closedresolution: fixedstage: needs patch -> resolved
2019-07-16 23:50:07 Jeffrey.Kintscher set messages: +
2019-06-06 00:06:25 Jeffrey.Kintscher set nosy: + Jeffrey.Kintscher
2015-05-18 19:42:26 ned.deily set messages: +
2015-05-18 19:03:04 r.david.murray set messages: +
2015-05-18 18:16:27 ned.deily set versions: + Python 3.5nosy: + ned.deilymessages: + stage: needs patch
2015-05-18 17:31:13 r.david.murray set nosy: + r.david.murraymessages: +
2015-05-18 17:23:41 mew create