{{{
if not os.path.exists(path):
os.makedirs(path)
}}}
Can be simplified to:
{{{
os.makedirs(path, exist_ok=True
}}}
The `exist_ok` argument was added in Python 3.2:
https://docs.python.org/3/library/os.html#os.makedirs
The original pattern also has a potential race condition where a process
could create a directory at `path` after the check but before the
`os.makedirs()` call. If such a race condition were to occur, the Django
process would result in a `FileExistsError`. `os.makedirs` handles this
condition.
--
Ticket URL: <https://code.djangoproject.com/ticket/30147>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/10919
--
Ticket URL: <https://code.djangoproject.com/ticket/30147#comment:1>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"290d8471bba35980f3e228f9c171afc40f2550fa" 290d8471]:
{{{
#!CommitTicketReference repository=""
revision="290d8471bba35980f3e228f9c171afc40f2550fa"
Fixed #30147 -- Simplified directory creation with os.makedirs(...,
exist_ok=True).
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30147#comment:2>