diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -307,7 +307,7 @@ class vfs(abstractvfs): if basename: if atomictemp: if not os.path.isdir(dirname): - util.makedirs(dirname, self.createmode) + util.ensuredirs(dirname, self.createmode) return util.atomictempfile(f, mode, self.createmode) try: if 'w' in mode: @@ -326,7 +326,7 @@ class vfs(abstractvfs): raise nlink = 0 if not os.path.isdir(dirname): - util.makedirs(dirname, self.createmode) + util.ensuredirs(dirname, self.createmode) if nlink > 0: if self._trustnlink is None: self._trustnlink = nlink > 1 or util.checknlink(f) @@ -347,7 +347,7 @@ class vfs(abstractvfs): dirname = os.path.dirname(linkname) if not os.path.exists(dirname): - util.makedirs(dirname, self.createmode) + util.ensuredirs(dirname, self.createmode) if self._cansymlink: try: diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -880,6 +880,16 @@ def makedirs(name, mode=None): 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: