Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: tools/generate_stubs/generate_stubs.py

Issue 10051026: avoid race between dir existence check and dir creation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/generate_stubs/generate_stubs.py
diff --git a/tools/generate_stubs/generate_stubs.py b/tools/generate_stubs/generate_stubs.py
index d2313a19a038a6df4eaa6fdf37b8b40a49a30a44..ff5b04a4e4abcf4587697e66268905a108199def 100755
--- a/tools/generate_stubs/generate_stubs.py
+++ b/tools/generate_stubs/generate_stubs.py
@@ -924,6 +924,18 @@ def ParseOptions():
return options, args
+def EnsureDirExists(dir):
+ """Creates a directory. Does not use the more obvious 'if not exists: create'
+ to avoid race with other invocations of the same code, which will error out
+ on makedirs if another invocation has succeeded in creating the directory
+ since the existence check."""
+ try:
+ os.makedirs(dir)
+ except:
+ if not os.path.isdir(dir):
+ raise
+
+
def CreateOutputDirectories(options):
"""Creates the intermediate and final output directories.
@@ -942,10 +954,8 @@ def CreateOutputDirectories(options):
if intermediate_dir is None:
intermediate_dir = out_dir
- if not os.path.exists(out_dir):
- os.makedirs(out_dir)
- if not os.path.exists(intermediate_dir):
- os.makedirs(intermediate_dir)
+ EnsureDirExists(out_dir)
+ EnsureDirExists(intermediate_dir)
return out_dir, intermediate_dir
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698