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:
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
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():
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)):