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