From ecae0841b13ac9e59fb51fc1714479270b66356c Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 22 Dec 2020 22:26:52 +0100 Subject: [PATCH 1/4] extract: add generic exception handler when setting xattrs, fixes #5092 emit a warning message giving the path, xattr key and error message. also: continue trying to restore other xattrs and bsdflags afterwards (it did not continue with this before this fix). --- src/borg/xattr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/borg/xattr.py b/src/borg/xattr.py index 5bfc1b677..e70be001f 100644 --- a/src/borg/xattr.py +++ b/src/borg/xattr.py @@ -147,5 +147,5 @@ def set_all(path, xattrs, follow_symlinks=False): logger.warning('%s: No space left on device while setting extended attribute %s (len = %d)' % ( path_str, k_str, len(v))) else: - raise + logger.warning('%s: when setting extended attribute %s: %s' % (path_str, k_str, str(e))) return warning From d986114e5eb306d91a75cd4178e831d555d1af61 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 25 Dec 2020 19:30:05 +0100 Subject: [PATCH 2/4] refactor/dedup xattr exception handler --- src/borg/xattr.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/borg/xattr.py b/src/borg/xattr.py index e70be001f..41a07cd74 100644 --- a/src/borg/xattr.py +++ b/src/borg/xattr.py @@ -133,19 +133,19 @@ def set_all(path, xattrs, follow_symlinks=False): path_str = '' % path else: path_str = os.fsdecode(path) + msg_format = '%s: when setting extended attribute %s: %%s' % (path_str, k_str) if e.errno == errno.E2BIG: - logger.warning('%s: Value or key of extended attribute %s is too big for this filesystem' % ( - path_str, k_str)) + err_str = 'too big for this filesystem' elif e.errno == errno.ENOTSUP: - logger.warning('%s: Extended attributes are not supported on this filesystem' % path_str) - 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)) + err_str = 'xattrs not supported on this filesystem' elif e.errno == errno.ENOSPC: # 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). - logger.warning('%s: No space left on device while setting extended attribute %s (len = %d)' % ( - path_str, k_str, len(v))) + err_str = 'no space left on device [xattr len = %d]' % (len(v),) else: - logger.warning('%s: when setting extended attribute %s: %s' % (path_str, k_str, str(e))) + # generic handler + # EACCES: permission denied to set this specific xattr (this may happen related to security.* keys) + # EPERM: operation not permitted + err_str = str(e) + logger.warning(msg_format % err_str) return warning From 2dbdaebd8a8b3f65649b87531ef1f2b187320a83 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 25 Dec 2020 19:35:27 +0100 Subject: [PATCH 3/4] fix tests for new xattr exception handler, see #5583 --- src/borg/testsuite/archiver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index 661f5fb40..c978ba280 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -1370,15 +1370,15 @@ class ArchiverTestCase(ArchiverTestCaseBase): input_abspath = os.path.abspath('input/file') with patch.object(xattr, 'setxattr', patched_setxattr_E2BIG): 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) with patch.object(xattr, 'setxattr', patched_setxattr_ENOTSUP): 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) with patch.object(xattr, 'setxattr', patched_setxattr_EACCES): 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) def test_path_normalization(self): From 227dccdfdc5e1249bc05a8fdea0c5a32c90f5e2c Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 25 Dec 2020 19:36:37 +0100 Subject: [PATCH 4/4] use strerror(e.errno) to get verbose error msg otherwise it is just like: [Errno NN] Exxxxx --- src/borg/xattr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/borg/xattr.py b/src/borg/xattr.py index 41a07cd74..f1942a996 100644 --- a/src/borg/xattr.py +++ b/src/borg/xattr.py @@ -146,6 +146,6 @@ def set_all(path, xattrs, follow_symlinks=False): # generic handler # EACCES: permission denied to set this specific xattr (this may happen related to security.* keys) # EPERM: operation not permitted - err_str = str(e) + err_str = os.strerror(e.errno) logger.warning(msg_format % err_str) return warning