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

login
register
mail settings
Submitter Jun Wu
Date March 12, 2017, 9:23 a.m.
Message ID <10ec43758c6b4034a0ee.1489310634@localhost.localdomain>
Download mbox | patch
Permalink /patch/19141/
State Changes Requested
Headers show

Comments

Jun Wu - March 12, 2017, 9:23 a.m.
# HG changeset patch
# User Jun Wu <quark@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

Patch

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: