]> arthur.barton.de Git - bup.git/commitdiff
metadata: don't die if Linux attr (not xattr) support is missing.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Mar 2011 08:38:07 +0000 (01:38 -0700)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Mar 2011 09:42:10 +0000 (02:42 -0700)
We don't need an import warning for this one, since linuxattr support is
always available on linux, and never available elsewhere, since it's in
_helpers.c and there are no special python modules to install.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/metadata.py
lib/bup/t/tmetadata.py

index 041d3e717d27375ca00f73eded79d9b45ab6adbf..8d0012086545c70b9706fdec3fa841038483d517 100644 (file)
@@ -29,8 +29,14 @@ try:
 except ImportError:
     log('Warning: POSIX ACL support missing; install python-pylibacl.\n')
     posix1e = None
-if _helpers.get_linux_file_attr:
+try:
     from bup._helpers import get_linux_file_attr, set_linux_file_attr
+except ImportError:
+    # No need for a warning here; the only reason they won't exist is that we're
+    # not on Linux, in which case files don't have any linux attrs anyway, so
+    # lacking the functions isn't a problem.
+    get_linux_file_attr = set_linux_file_attr = None
+    
 
 # WARNING: the metadata encoding is *not* stable yet.  Caveat emptor!
 
@@ -429,6 +435,7 @@ class Metadata:
     ## Linux attributes (lsattr(1), chattr(1))
 
     def _add_linux_attr(self, path, st):
+        if not get_linux_file_attr: return
         if stat.S_ISREG(st.st_mode) or stat.S_ISDIR(st.st_mode):
             try:
                 attr = get_linux_file_attr(path)
@@ -454,6 +461,10 @@ class Metadata:
 
     def _apply_linux_attr_rec(self, path, restore_numeric_ids=False):
         if self.linux_attr:
+            if not set_linux_file_attr:
+                add_error("%s: can't restore linuxattrs: "
+                          "linuxattr support missing.\n" % path)
+                return
             set_linux_file_attr(path, self.linux_attr)
 
 
index a5f7a4f2eac364061c311989ab7b94aeb5b8e7dc..f55f7e36e7491890bca2b4b67eafb38cc4fd1ddf 100644 (file)
@@ -120,9 +120,10 @@ def test_from_path_error():
         WVPASSEQ(m.path, path)
         subprocess.call(['chmod', '000', path])
         metadata.from_path(path, archive_path=path, save_symlinks=True)
-        errmsg = helpers.saved_errors[0] if helpers.saved_errors else ''
-        WVPASS(errmsg.startswith('read Linux attr'))
-        clear_errors()
+        if metadata.get_linux_file_attr:
+            errmsg = helpers.saved_errors[0] if helpers.saved_errors else ''
+            WVPASS(errmsg.startswith('read Linux attr'))
+            clear_errors()
     finally:
         subprocess.call(['rm', '-rf', tmpdir])