Repository: borgbackup/borg

Issue:
failure with eatmydata "tried to call a logger before setup_logging() was called"
As said on Debian bug 825729, with eatmydata borg fails.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=825729

```
==================================== ERRORS ====================================
___ ERROR collecting .pybuild/pythonX.Y_3.5/build/borg/testsuite/__init__.py ___
borg/testsuite/__init__.py:10: in <module>
    from ..xattr import get_all
borg/xattr.py:71: in <module>
    logger.error(msg)
borg/logger.py:173: in error
    return self.__logger.error(*args, **kw)
borg/logger.py:150: in __logger
    raise Exception("tried to call a logger before setup_logging() was called")
E   Exception: tried to call a logger before setup_logging() was called
--------------------------------------------------------------------------------
```



Discussion:
I've  no idea what eatmydata is, but it seems to invoke borg / tests in an unusual way.
grep the borg source for `setup_logging` to see what you need to add?

package description:

```
Library and utilities designed to disable fsync and friends
This package contains a small LD_PRELOAD library (libeatmydata) and a couple of helper utilities designed to transparently disable fsync and friends (like open(O_SYNC)). This has two side-effects: making software that writes data safely to disk a lot quicker and making this software no longer crash safe.
You will find eatmydata useful if particular software calls fsync(), sync() etc. frequently but the data it stores is not that valuable to you and you may afford losing it in case of system crash. Data-to-disk synchronization calls are typically very slow on modern file systems and their extensive usage might slow down software significantly. It does not make sense to accept such a hit in performance if data being manipulated is not very important.
On the other hand, do not use eatmydata when you care about what software stores or it manipulates important components of your system. The library is called libEAT-MY-DATA for a reason. 
```

Not sure if fixable or worth a fix :)

> Not sure if fixable or worth a fix :)

Not worth a fix. fsync()iness is "fixed" in 1.1.

Edit: Disabling fsync() is a _really_ bad idea for Borg.

~~-- Does it crash at runtime? If not we might want to add a little code to make it...~~ Traceback suggests just that, nothing to do there.

Close?


Resolving patch:
diff --git a/src/borg/xattr.py b/src/borg/xattr.py
--- a/src/borg/xattr.py
+++ b/src/borg/xattr.py
@@ -2,6 +2,7 @@
 """
 import errno
 import os
+import re
 import subprocess
 import sys
 import tempfile
@@ -52,17 +53,20 @@ def get_all(path, follow_symlinks=True):
 # 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.
-LD_PRELOAD = os.environ.get('LD_PRELOAD', '')
 XATTR_FAKEROOT = False
-if sys.platform.startswith('linux') and 'fakeroot' in LD_PRELOAD:
-    fakeroot_version = LooseVersion(subprocess.check_output(['fakeroot', '-v']).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 = LD_PRELOAD
-        XATTR_FAKEROOT = True
-
+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"):
+            fakeroot_version = LooseVersion(subprocess.check_output(['fakeroot', '-v']).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
 
 try:
     libc = CDLL(libc_name, use_errno=True)


Test patch: