Patchwork D10841: copyfiles: deal with existing file when hardlinking

login
register
mail settings
Submitter phabricator
Date June 9, 2021, 2:37 p.m.
Message ID <differential-rev-PHID-DREV-sj3zqy2nk4ftu4aehiib-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49165/
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
  If the hardlinking fails, we fallback to `shutil.copy`, but do not consider
  future hardlinking doomed.
  
  This is a slight improvement from the current situation, we still avoid
  hardliking in a case we might be able to do it. However this does not have an
  impact of the rest of the operation.
  
  (This is an opportunity improvement while looking at something next to that.)

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2009,8 +2009,10 @@ 
         if hardlink:
             try:
                 oslink(src, dst)
-            except (IOError, OSError):
-                hardlink = False
+            except (IOError, OSError) as exc:
+                if exc.errno != errno.EEXIST:
+                    hardlink = False
+                # XXX maybe try to relink if the file exist ?
                 shutil.copy(src, dst)
         else:
             shutil.copy(src, dst)