diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-30 19:51:27 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-30 19:51:27 +0000 |
commit | d1f4b72d81f4cd659893f283311ac8bb5f24178d (patch) | |
tree | ab51fbc2345b9ca1d05cb46b179a63374f64b5ae /tools/generate_stubs | |
parent | efba87c4709424032390c8d18a51a2651725dd3b (diff) | |
download | chromium_src-d1f4b72d81f4cd659893f283311ac8bb5f24178d.zip chromium_src-d1f4b72d81f4cd659893f283311ac8bb5f24178d.tar.gz chromium_src-d1f4b72d81f4cd659893f283311ac8bb5f24178d.tar.bz2 |
avoid race between dir existence check and dir creation
On clean builds, if there's two instances running at the same time makedirs occasionally raises and kills the build.
R=ajwong@chromium.org
Review URL: http://codereview.chromium.org/10051026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134571 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/generate_stubs')
-rwxr-xr-x | tools/generate_stubs/generate_stubs.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/tools/generate_stubs/generate_stubs.py b/tools/generate_stubs/generate_stubs.py index d2313a1..61d606b 100755 --- a/tools/generate_stubs/generate_stubs.py +++ b/tools/generate_stubs/generate_stubs.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -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 |