comparison mercurial/hg.py @ 47416:1c7f3d911d0f

clone: cleanup the "cleanup dir" logic used during local clone With the previous code, there was a small windows were we could delete too much data. This should no longer be the case. (This is an opportunity improvement while looking at something next to that.) Differential Revision: https://phab.mercurial-scm.org/D10840
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 08 Jun 2021 03:40:36 +0200
parents 7edaf91c7886
children d1c1fd7ac46d
comparison
equal deleted inserted replaced
47415:b1b3127227be 47416:1c7f3d911d0f
823 abspath = origsource 823 abspath = origsource
824 if islocal(origsource): 824 if islocal(origsource):
825 abspath = os.path.abspath(urlutil.urllocalpath(origsource)) 825 abspath = os.path.abspath(urlutil.urllocalpath(origsource))
826 826
827 if islocal(dest): 827 if islocal(dest):
828 cleandir = dest 828 if os.path.exists(dest):
829 # only clean up directories we create ourselves
830 hgdir = os.path.realpath(os.path.join(dest, b".hg"))
831 cleandir = hgdir
832 else:
833 cleandir = dest
829 834
830 copy = False 835 copy = False
831 if ( 836 if (
832 srcrepo 837 srcrepo
833 and srcrepo.cancopy() 838 and srcrepo.cancopy()
853 if copy: 858 if copy:
854 srcrepo.hook(b'preoutgoing', throw=True, source=b'clone') 859 srcrepo.hook(b'preoutgoing', throw=True, source=b'clone')
855 hgdir = os.path.realpath(os.path.join(dest, b".hg")) 860 hgdir = os.path.realpath(os.path.join(dest, b".hg"))
856 if not os.path.exists(dest): 861 if not os.path.exists(dest):
857 util.makedirs(dest) 862 util.makedirs(dest)
858 else:
859 # only clean up directories we create ourselves
860 cleandir = hgdir
861 try: 863 try:
862 destpath = hgdir 864 destpath = hgdir
863 util.makedir(destpath, notindexed=True) 865 util.makedir(destpath, notindexed=True)
864 except OSError as inst: 866 except OSError as inst:
865 if inst.errno == errno.EEXIST: 867 if inst.errno == errno.EEXIST: