From eaf137bb418988a8a727722b3112c688d967702c Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 20 Mar 2011 01:38:07 -0700 Subject: [PATCH] metadata: don't die if Linux attr (not xattr) support is missing. 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 --- lib/bup/metadata.py | 13 ++++++++++++- lib/bup/t/tmetadata.py | 7 ++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py index 041d3e7..8d00120 100644 --- a/lib/bup/metadata.py +++ b/lib/bup/metadata.py @@ -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) diff --git a/lib/bup/t/tmetadata.py b/lib/bup/t/tmetadata.py index a5f7a4f..f55f7e3 100644 --- a/lib/bup/t/tmetadata.py +++ b/lib/bup/t/tmetadata.py @@ -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]) -- 2.39.5