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.
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?
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.
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 ...
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