• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import errno
6import os.path
7
8def EnsureDirectoryExists(path, always_try_to_create=False):
9  """A wrapper for os.makedirs that does not error if the directory already
10  exists. A different process could be racing to create this directory."""
11
12  if not os.path.exists(path) or always_try_to_create:
13    try:
14      os.makedirs(path)
15    except OSError as e:
16      # There may have been a race to create this directory.
17      if e.errno != errno.EEXIST:
18        raise
19