From patchwork Sun Mar 12 09:23:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5, of, 7, V3] util: disable hardlink for copyfile if fstype is outside a whitelist From: Jun Wu X-Patchwork-Id: 19141 Message-Id: <10ec43758c6b4034a0ee.1489310634@localhost.localdomain> To: Date: Sun, 12 Mar 2017 01:23:54 -0800 # HG changeset patch # User Jun Wu # 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: