comparison 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
comparison
equal deleted inserted replaced
18667:f12804d3ff80 18668:4034b8d551b1
878 makedirs(parent, mode) 878 makedirs(parent, mode)
879 os.mkdir(name) 879 os.mkdir(name)
880 if mode is not None: 880 if mode is not None:
881 os.chmod(name, mode) 881 os.chmod(name, mode)
882 882
883 def ensuredirs(name, mode=None):
884 """race-safe recursive directory creation"""
885 try:
886 makedirs(name, mode)
887 except OSError, err:
888 if err.errno == errno.EEXIST and os.path.isdir(name):
889 # someone else seems to have won a directory creation race
890 return
891 raise
892
883 def readfile(path): 893 def readfile(path):
884 fp = open(path, 'rb') 894 fp = open(path, 'rb')
885 try: 895 try:
886 return fp.read() 896 return fp.read()
887 finally: 897 finally: