Browse Source

re-add the code that checks if we run under fakeroot, fixes #4291

code taken from 1.1-maint.

running as a user, with or without fakeroot does not have the test
fails in test_extract_capabilities any more.
Thomas Waldmann 6 years ago
parent
commit
12a18b955e
1 changed files with 27 additions and 1 deletions
  1. 27 1
      src/borg/xattr.py

+ 27 - 1
src/borg/xattr.py

@@ -2,15 +2,41 @@
 
 
 import errno
 import errno
 import os
 import os
+import re
+import subprocess
+import sys
 import tempfile
 import tempfile
 
 
+from distutils.version import LooseVersion
+
+from .helpers import prepare_subprocess_env
+
 from .logger import create_logger
 from .logger import create_logger
 
 
 logger = create_logger()
 logger = create_logger()
 
 
 from .platform import listxattr, getxattr, setxattr, ENOATTR
 from .platform import listxattr, getxattr, setxattr, ENOATTR
 
 
-XATTR_FAKEROOT = True  # fakeroot with xattr support required (>= 1.20.2?)
+# If we are running with fakeroot on Linux, then use the xattr functions of fakeroot. This is needed by
+# the 'test_extract_capabilities' test, but also allows xattrs to work with fakeroot on Linux in normal use.
+# TODO: Check whether fakeroot supports xattrs on all platforms supported below.
+# TODO: If that's the case then we can make Borg fakeroot-xattr-compatible on these as well.
+XATTR_FAKEROOT = False
+if sys.platform.startswith('linux'):
+    LD_PRELOAD = os.environ.get('LD_PRELOAD', '')
+    preloads = re.split("[ :]", LD_PRELOAD)
+    for preload in preloads:
+        if preload.startswith("libfakeroot"):
+            env = prepare_subprocess_env(system=True)
+            fakeroot_output = subprocess.check_output(['fakeroot', '-v'], env=env)
+            fakeroot_version = LooseVersion(fakeroot_output.decode('ascii').split()[-1])
+            if fakeroot_version >= LooseVersion("1.20.2"):
+                # 1.20.2 has been confirmed to have xattr support
+                # 1.18.2 has been confirmed not to have xattr support
+                # Versions in-between are unknown
+                libc_name = preload
+                XATTR_FAKEROOT = True
+            break
 
 
 
 
 def is_enabled(path=None):
 def is_enabled(path=None):