Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Commit

Permalink
Fixed directory creation race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael Johansson committed Dec 7, 2015
1 parent 8f36974 commit 1ab1ba2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lighter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ def parse_service(filename, targetdir=None):
# Write json file to disk for logging purposes
if targetdir:
outputfile = os.path.join(targetdir, filename + '.json')
if not os.path.exists(os.path.dirname(outputfile)):

# Exception if directory exists, e.g. because another thread created it concurrently
try:
os.makedirs(os.path.dirname(outputfile))
except OSError, e:
pass

with open(outputfile, 'w') as fd:
fd.write(json.dumps(config, indent=4))

Expand Down

0 comments on commit 1ab1ba2

Please sign in to comment.