]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
_apply_linux_xattr_rec(): do nothing if no rec; fix restricted access test.
authorRob Browning <rlb@defaultvalue.org>
Tue, 5 Nov 2013 22:17:04 +0000 (16:17 -0600)
committerRob Browning <rlb@defaultvalue.org>
Tue, 5 Nov 2013 22:17:04 +0000 (16:17 -0600)
If the metadata object has no linux_xattr, don't do anything at all in
_apply_linux_xattr_rec(), and don't test the filesystem for xattr
support to determine whether or not to expect an xattr error, because
EACCES trumps the other errors.

This should be more efficient and fix a
test_apply_to_path_restricted_access() failure.

Thanks to Sebastian Schumb <sebastian@sebastians-site.de> for
reporting the problem and helping track down the fix.

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

index 20eb57bce927da3829726c7c7b8be526a181f9e9..e6887247803603b222149eb07e1ba887f95c246f 100644 (file)
@@ -637,6 +637,8 @@ class Metadata:
                 add_error("%s: can't restore xattr; xattr support missing.\n"
                           % path)
             return
+        if not self.linux_xattr:
+            return
         try:
             existing_xattrs = set(xattr.list(path, nofollow=True))
         except IOError, e:
@@ -644,27 +646,26 @@ class Metadata:
                 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 \
-                        or v != xattr.get(path, k, nofollow=True):
-                    try:
-                        xattr.set(path, k, v, nofollow=True)
-                    except IOError, e:
-                        if e.errno == errno.EPERM \
-                                or e.errno == errno.EOPNOTSUPP:
-                            raise ApplyError('xattr.set: %s' % e)
-                        else:
-                            raise
-                existing_xattrs -= frozenset([k])
-            for k in existing_xattrs:
+        for k, v in self.linux_xattr:
+            if k not in existing_xattrs \
+                    or v != xattr.get(path, k, nofollow=True):
                 try:
-                    xattr.remove(path, k, nofollow=True)
+                    xattr.set(path, k, v, nofollow=True)
                 except IOError, e:
-                    if e.errno == errno.EPERM:
-                        raise ApplyError('xattr.remove: %s' % e)
+                    if e.errno == errno.EPERM \
+                            or e.errno == errno.EOPNOTSUPP:
+                        raise ApplyError('xattr.set: %s' % e)
                     else:
                         raise
+            existing_xattrs -= frozenset([k])
+        for k in existing_xattrs:
+            try:
+                xattr.remove(path, k, nofollow=True)
+            except IOError, e:
+                if e.errno == errno.EPERM:
+                    raise ApplyError('xattr.remove: %s' % e)
+                else:
+                    raise
 
     def __init__(self):
         self.mode = None
index ea34f297dcc260839e68811ddfdab39d9b7be578..99784078d20fd03016606d4422587264a5c9972c 100644 (file)
@@ -189,20 +189,6 @@ def _linux_attr_supported(path):
     return True
 
 
-def _linux_xattr_supported(path):
-    # NOTE: destructive test (tries to write to path).
-    if not metadata.xattr:
-        return False
-    try:
-        xattr.set(path, 'user.bup-test-xattr-support', 'true', nofollow=True)
-    except IOError, e:
-        if e.errno == errno.EOPNOTSUPP:
-            return False
-        else:
-            raise
-    return True
-
-
 @wvtest
 def test_apply_to_path_restricted_access():
     if is_superuser() or detect_fakeroot():
@@ -224,7 +210,7 @@ def test_apply_to_path_restricted_access():
         expected_errors = ['utime: ']
         if m.linux_attr and _linux_attr_supported(tmpdir):
             expected_errors.append('Linux chattr: ')
-        if _linux_xattr_supported(tmpdir):
+        if metadata.xattr and m.linux_xattr:
             expected_errors.append('xattr.set: ')
         WVPASS(len(helpers.saved_errors) == len(expected_errors))
         for i in xrange(len(expected_errors)):