Merge pull request #5592 from ThomasWaldmann/extract-xattr-eperm-master

extract: improve setxattr exception handling
This commit is contained in:
TW 2020-12-25 20:52:04 +01:00 committed by GitHub
commit 050a705010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -1370,15 +1370,15 @@ class ArchiverTestCase(ArchiverTestCaseBase):
input_abspath = os.path.abspath('input/file') input_abspath = os.path.abspath('input/file')
with patch.object(xattr, 'setxattr', patched_setxattr_E2BIG): with patch.object(xattr, 'setxattr', patched_setxattr_E2BIG):
out = self.cmd('extract', self.repository_location + '::test', exit_code=EXIT_WARNING) out = self.cmd('extract', self.repository_location + '::test', exit_code=EXIT_WARNING)
assert '>: Value or key of extended attribute user.attribute is too big for this filesystem\n' in out assert ': when setting extended attribute user.attribute: too big for this filesystem\n' in out
os.remove(input_abspath) os.remove(input_abspath)
with patch.object(xattr, 'setxattr', patched_setxattr_ENOTSUP): with patch.object(xattr, 'setxattr', patched_setxattr_ENOTSUP):
out = self.cmd('extract', self.repository_location + '::test', exit_code=EXIT_WARNING) out = self.cmd('extract', self.repository_location + '::test', exit_code=EXIT_WARNING)
assert '>: Extended attributes are not supported on this filesystem\n' in out assert ': when setting extended attribute user.attribute: xattrs not supported on this filesystem\n' in out
os.remove(input_abspath) os.remove(input_abspath)
with patch.object(xattr, 'setxattr', patched_setxattr_EACCES): with patch.object(xattr, 'setxattr', patched_setxattr_EACCES):
out = self.cmd('extract', self.repository_location + '::test', exit_code=EXIT_WARNING) out = self.cmd('extract', self.repository_location + '::test', exit_code=EXIT_WARNING)
assert '>: Permission denied when setting extended attribute user.attribute\n' in out assert ': when setting extended attribute user.attribute: Permission denied\n' in out
assert os.path.isfile(input_abspath) assert os.path.isfile(input_abspath)
def test_path_normalization(self): def test_path_normalization(self):

View File

@ -133,19 +133,19 @@ def set_all(path, xattrs, follow_symlinks=False):
path_str = '<FD %d>' % path path_str = '<FD %d>' % path
else: else:
path_str = os.fsdecode(path) path_str = os.fsdecode(path)
msg_format = '%s: when setting extended attribute %s: %%s' % (path_str, k_str)
if e.errno == errno.E2BIG: if e.errno == errno.E2BIG:
logger.warning('%s: Value or key of extended attribute %s is too big for this filesystem' % ( err_str = 'too big for this filesystem'
path_str, k_str))
elif e.errno == errno.ENOTSUP: elif e.errno == errno.ENOTSUP:
logger.warning('%s: Extended attributes are not supported on this filesystem' % path_str) err_str = 'xattrs not supported on this filesystem'
elif e.errno == errno.EACCES:
# permission denied to set this specific xattr (this may happen related to security.* keys)
logger.warning('%s: Permission denied when setting extended attribute %s' % (path_str, k_str))
elif e.errno == errno.ENOSPC: elif e.errno == errno.ENOSPC:
# ext4 reports ENOSPC when trying to set an xattr with >4kiB while ext4 can only support 4kiB xattrs # ext4 reports ENOSPC when trying to set an xattr with >4kiB while ext4 can only support 4kiB xattrs
# (in this case, this is NOT a "disk full" error, just a ext4 limitation). # (in this case, this is NOT a "disk full" error, just a ext4 limitation).
logger.warning('%s: No space left on device while setting extended attribute %s (len = %d)' % ( err_str = 'no space left on device [xattr len = %d]' % (len(v),)
path_str, k_str, len(v)))
else: else:
raise # generic handler
# EACCES: permission denied to set this specific xattr (this may happen related to security.* keys)
# EPERM: operation not permitted
err_str = os.strerror(e.errno)
logger.warning(msg_format % err_str)
return warning return warning