Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 18668:4034b8d551b1
scmutil: create directories in a race-safe way during update
With the new parallel update code, it is possible for multiple
workers to try to create a hierarchy of directories at the same
time. This is hard to trigger in general, but most likely during
initial checkout.
To deal with these races, we introduce a new ensuredirs function
whose contract is to ensure that a directory hierarchy exists - it
will ignore a failure that implies that the desired directory already
exists.
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Mon, 11 Feb 2013 16:15:12 -0800 |
parents | b2586e2cc67a |
children | 423eee0b0b14 |
line wrap: on
line diff
--- a/mercurial/util.py Mon Feb 11 14:50:54 2013 -0800 +++ b/mercurial/util.py Mon Feb 11 16:15:12 2013 -0800 @@ -880,6 +880,16 @@ if mode is not None: os.chmod(name, mode) +def ensuredirs(name, mode=None): + """race-safe recursive directory creation""" + try: + makedirs(name, mode) + except OSError, err: + if err.errno == errno.EEXIST and os.path.isdir(name): + # someone else seems to have won a directory creation race + return + raise + def readfile(path): fp = open(path, 'rb') try: