Patchwork D10840: clone: cleanup the "cleanup dir" logic used during local clone

login
register
mail settings
Submitter phabricator
Date June 9, 2021, 2:37 p.m.
Message ID <differential-rev-PHID-DREV-c6ydygz4dmugdqlwecsg-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49161/
State Superseded
Headers show

Comments

phabricator - June 9, 2021, 2:37 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.)

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10840

AFFECTED FILES
  mercurial/hg.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -825,7 +825,12 @@ 
             abspath = os.path.abspath(urlutil.urllocalpath(origsource))
 
         if islocal(dest):
-            cleandir = dest
+            if os.path.exists(dest):
+                # only clean up directories we create ourselves
+                hgdir = os.path.realpath(os.path.join(dest, b".hg"))
+                cleandir = hgdir
+            else:
+                cleandir = dest
 
         copy = False
         if (
@@ -855,9 +860,6 @@ 
             hgdir = os.path.realpath(os.path.join(dest, b".hg"))
             if not os.path.exists(dest):
                 util.makedirs(dest)
-            else:
-                # only clean up directories we create ourselves
-                cleandir = hgdir
             try:
                 destpath = hgdir
                 util.makedir(destpath, notindexed=True)