[PATCH 5 of 7 V3] util: disable hardlink for copyfile if fstype is outside a whitelist

Jun Wu quark at fb.com
Sun Mar 12 05:23:54 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1489306987 28800
#      Sun Mar 12 00:23:07 2017 -0800
# Node ID 10ec43758c6b4034a0eeecf24a54752784c82a2c
# Parent  cd3743a4b74ef409de34ec002a469201cd39b30e
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 10ec43758c6b
util: disable hardlink for copyfile if fstype is outside a whitelist

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1063,4 +1063,13 @@ def checksignature(func):
 allowhardlinks = False
 
+# a whilelist of known filesystems where hardlink works reliably
+_hardlinkfswhitelist = set([
+    'btrfs',
+    'ext3',
+    'ext4',
+    'tmpfs',
+    'xfs',
+])
+
 def copyfile(src, dest, hardlink=False, copystat=False, checkambig=False):
     '''copy a file, preserving mode and optionally other stat info like
@@ -1079,4 +1088,10 @@ def copyfile(src, dest, hardlink=False, 
             oldstat = checkambig and filestat(dest)
         unlink(dest)
+    if hardlink:
+        # Hardlinks are problematic on CIFS (issue4546), do not allow hardlinks
+        # unless we are confident that dest is on a whitelisted filesystem.
+        fstype = getfstype(dest)
+        if fstype not in _hardlinkfswhitelist:
+            hardlink = False
     if allowhardlinks and hardlink:
         try:


More information about the Mercurial-devel mailing list