Skip to content

Commit

Permalink
Fix race condition in doit.tools.create_folder
Browse files Browse the repository at this point in the history
`create_folder` had a race condition: if many tasks try to create the same folder then it is possible that between checking directory existence and actual creation of the directory in the next line another task will create that directory.
Since [python 3.2](https://docs.python.org/3.4/library/os.html#os.makedirs) `os.makedirs` has nice `exist_ok` argument that will do the same thing but without such problems.
  • Loading branch information
Hinidu authored and schettino72 committed Apr 3, 2016
1 parent 773a4a4 commit 169a1df
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ Changes
- fix GH-#99: positional argument on tasks not specified from cmd-line
- fix GH-#97: `list` command does not display task-doc for `DelayedTask`
when `creates` is specified
- fix GH-#131: race condition in doit.tools.create_folder
- GH-#114: `file_dep`, `targets` and `CmdAction` support pathlib.



0.29.0 (*2015-08-16*)
=====================

Expand Down
3 changes: 1 addition & 2 deletions doit/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
# action
def create_folder(dir_path):
"""create a folder in the given path if it doesnt exist yet."""
if not (os.path.exists(dir_path) and os.path.isdir(dir_path)):
os.makedirs(dir_path)
os.makedirs(dir_path, exist_ok=True)


# title
Expand Down

0 comments on commit 169a1df

Please sign in to comment.