Mercurial > hg
changeset 5569:9e209193f18d
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.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 02 Dec 2007 13:37:30 -0600 |
parents | de620356064f |
children | 78a6b985882f |
files | mercurial/hg.py |
diffstat | 1 files changed, 17 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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: