]> arthur.barton.de Git - bup.git/commitdiff
Fix xattr tests and bugs revealed (fully remove set -e from test-meta.sh).
authorRob Browning <rlb@defaultvalue.org>
Sun, 27 Oct 2013 18:23:20 +0000 (13:23 -0500)
committerRob Browning <rlb@defaultvalue.org>
Fri, 1 Nov 2013 23:24:16 +0000 (18:24 -0500)
Fixing the xattr tests to run correctly pointed out that bup stops
trying to apply metadata after the first failure (i.e. after any
metadata record application fails).  Change it so that bup always
tries every metadata record.  Otherwise, bup may skip some forms of
metadata without any notification -- and it shouldn't.  For example,
it shouldn't skip ACLs just because the current filesystem doesn't
support xattrs.

Fix two additional problems that were exposed by the changes described
above.

Check for EACCES when trying to apply an attr record, and properly
convert it to an ApplyError.  This problem was revealed by
test_apply_to_path_restricted_access.

Check for EACCES when trying to read the current filesystem xattrs
during the process of applying the metadata xattrs, and when
encountered, convert it to an ApplyError.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/metadata.py
lib/bup/t/tmetadata.py
t/test-meta.sh

index 3aa5f4da8219fb6defff6dc67f301aa493c26175..20eb57bce927da3829726c7c7b8be526a181f9e9 100644 (file)
@@ -591,7 +591,8 @@ class Metadata:
             try:
                 set_linux_file_attr(path, self.linux_attr)
             except OSError, e:
-                if e.errno in (errno.ENOTTY, errno.EOPNOTSUPP, errno.ENOSYS):
+                if e.errno in (errno.ENOTTY, errno.EOPNOTSUPP, errno.ENOSYS,
+                               errno.EACCES):
                     raise ApplyError('Linux chattr: %s' % e)
                 else:
                     raise
@@ -636,7 +637,13 @@ class Metadata:
                 add_error("%s: can't restore xattr; xattr support missing.\n"
                           % path)
             return
-        existing_xattrs = set(xattr.list(path, nofollow=True))
+        try:
+            existing_xattrs = set(xattr.list(path, nofollow=True))
+        except IOError, e:
+            if e.errno == errno.EACCES:
+                raise ApplyError('xattr.set: %s' % e)
+            else:
+                raise
         if self.linux_xattr:
             for k, v in self.linux_xattr:
                 if k not in existing_xattrs \
@@ -743,13 +750,14 @@ class Metadata:
                       + ' with unrecognized mode "0x%x"\n' % self.mode)
             return
         num_ids = restore_numeric_ids
-        try:
-            self._apply_common_rec(path, restore_numeric_ids=num_ids)
-            self._apply_posix1e_acl_rec(path, restore_numeric_ids=num_ids)
-            self._apply_linux_attr_rec(path, restore_numeric_ids=num_ids)
-            self._apply_linux_xattr_rec(path, restore_numeric_ids=num_ids)
-        except ApplyError, e:
-            add_error(e)
+        for apply_metadata in (self._apply_common_rec,
+                               self._apply_posix1e_acl_rec,
+                               self._apply_linux_attr_rec,
+                               self._apply_linux_xattr_rec):
+            try:
+                apply_metadata(path, restore_numeric_ids=num_ids)
+            except ApplyError, e:
+                add_error(e)
 
     def same_file(self, other):
         """Compare this to other for equivalency.  Return true if
index 4e7884a808f167244629b1f10ed19a8bad962012..6f415b89768683a70f755df66a8a7d0e557ace17 100644 (file)
@@ -190,9 +190,11 @@ def test_apply_to_path_restricted_access():
         WVPASSEQ(m.path, path)
         os.chmod(tmpdir, 000)
         m.apply_to_path(path)
-        WVPASS(len(helpers.saved_errors) == 1)
-        errmsg = _first_err()
-        WVPASS(errmsg.startswith('utime: '))
+        print >> sys.stderr, helpers.saved_errors
+        WVPASS(len(helpers.saved_errors) == 3)
+        WVPASS(str(helpers.saved_errors[0]).startswith('utime: '))
+        WVPASS(str(helpers.saved_errors[1]).startswith('Linux chattr: '))
+        WVPASS(str(helpers.saved_errors[2]).startswith('xattr.set: '))
         clear_errors()
     finally:
         subprocess.call(['rm', '-rf', tmpdir])
index 33a51dddfc5d9d2bb6dcce8d321605ae5bd94200..879e108904fbb0923cd7c594f37b22ebaf8aaeb4 100755 (executable)
@@ -677,37 +677,29 @@ if [ $(t/root-status) == root ]; then
             ) || exit $?
         ) || exit $?
 
-        # FIXME: skip remaining tests until we fix them.
-        if ! test "$BUP_SKIP_BROKEN_TESTS"; then
-
-        set -e
-
         WVSTART 'meta - Linux xattr (as root)'
-        force-delete testfs/src
-        mkdir testfs/src
-        (
-            touch testfs/src/foo
-            mkdir testfs/src/bar
-            attr -s foo -V bar testfs/src/foo
-            attr -s foo -V bar testfs/src/bar
-            (cd testfs && test-src-create-extract)
+        WVPASS force-delete testfs/src
+        WVPASS mkdir testfs/src
+        WVPASS touch testfs/src/foo
+        WVPASS mkdir testfs/src/bar
+        WVPASS attr -s foo -V bar testfs/src/foo
+        WVPASS attr -s foo -V bar testfs/src/bar
+        (WVPASS cd testfs; WVPASS test-src-create-extract) || exit $?
 
-            # Test restoration to a limited filesystem (vfat).
-            (
-                WVPASS bup meta --create --recurse --file testfs/src.meta \
-                    testfs/src
-                force-delete testfs-limited/src-restore
-                mkdir testfs-limited/src-restore
-                cd testfs-limited/src-restore
-                WVFAIL bup meta --extract --file ../../testfs/src.meta 2>&1 \
-                    | WVPASS grep -e '^xattr\.set:' \
-                    | WVPASS python -c \
-                      'import sys; exit(not len(sys.stdin.readlines()) == 2)'
-            )
-        )
-        fi
+        # Test restoration to a limited filesystem (vfat).
+        (
+            WVPASS bup meta --create --recurse --file testfs/src.meta \
+                testfs/src
+            WVPASS force-delete testfs-limited/src-restore
+            WVPASS mkdir testfs-limited/src-restore
+            WVPASS cd testfs-limited/src-restore
+            WVFAIL bup meta --extract --file ../../testfs/src.meta
+            WVFAIL bup meta --extract --file ../../testfs/src.meta 2>&1 \
+                | WVPASS grep -e '^xattr\.set:' \
+                | WVPASS python -c \
+                'import sys; exit(not len(sys.stdin.readlines()) == 2)'
+        ) || exit $?
 
-        set +e
         WVSTART 'meta - POSIX.1e ACLs (as root)'
         WVPASS force-delete testfs/src
         WVPASS mkdir testfs/src