# HG changeset patch # User Matt Mackall # Date 1196624250 21600 # Node ID 9e209193f18dbaf07a787a5d4809ac39c23ec2d3 # Parent de620356064ff9dcebcb77b8595c34b40368c332 clone: fix race with same target directory (issue716) Whichever side creates .hg first wins the race, and the other aborts politely without deleting the tree. diff -r de620356064f -r 9e209193f18d mercurial/hg.py --- a/mercurial/hg.py Sat Dec 01 13:09:27 2007 -0600 +++ b/mercurial/hg.py Sun Dec 02 13:37:30 2007 -0600 @@ -173,8 +173,15 @@ src_store = os.path.realpath(src_repo.spath) if not os.path.exists(dest): os.mkdir(dest) - dest_path = os.path.realpath(os.path.join(dest, ".hg")) - os.mkdir(dest_path) + try: + dest_path = os.path.realpath(os.path.join(dest, ".hg")) + os.mkdir(dest_path) + except OSError, inst: + if inst.errno == errno.EEXIST: + dir_cleanup.close() + raise util.Abort(_("destination '%s' already exists") + % dest) + raise if src_repo.spath != src_repo.path: # XXX racy dummy_changelog = os.path.join(dest_path, "00changelog.i") @@ -203,7 +210,14 @@ dest_repo = repository(ui, dest) else: - dest_repo = repository(ui, dest, create=True) + try: + dest_repo = repository(ui, dest, create=True) + except OSError, inst: + if inst.errno == errno.EEXIST: + dir_cleanup.close() + raise util.Abort(_("destination '%s' already exists") + % dest) + raise revs = None if rev: