From 3e3ed78b8c3e38cdb57382f43db1f339ea2c9889 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Tue, 30 Nov 2021 20:51:38 +0300 Subject: [PATCH 1/2] Test % in file name and xattr (see #6063) --- src/borg/testsuite/archiver.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index d76527869..09378e655 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -3459,6 +3459,40 @@ id: 2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02 output = self.cmd(*args, fork=True, exit_code=2) assert 'Attic repository detected.' in output + # derived from test_extract_xattrs_errors() + @pytest.mark.xfail(raises=ValueError, strict=True) + @pytest.mark.skipif(not xattr.XATTR_FAKEROOT, reason='xattr not supported on this system or on this version of' + 'fakeroot') + def test_do_not_fail_when_percent_is_in_xattr_name(self): + """https://github.com/borgbackup/borg/issues/6063""" + def patched_setxattr_EACCES(*args, **kwargs): + raise OSError(errno.EACCES, 'EACCES') + + self.create_regular_file('file') + xattr.setxattr(b'input/file', b'user.attribute%p', b'value') + self.cmd('init', self.repository_location, '-e' 'none') + self.cmd('create', self.repository_location + '::test', 'input') + with changedir('output'): + with patch.object(xattr, 'setxattr', patched_setxattr_EACCES): + self.cmd('extract', self.repository_location + '::test', exit_code=EXIT_WARNING) + + # derived from test_extract_xattrs_errors() + @pytest.mark.xfail(raises=ValueError, strict=True) + @pytest.mark.skipif(not xattr.XATTR_FAKEROOT, reason='xattr not supported on this system or on this version of' + 'fakeroot') + def test_do_not_fail_when_percent_is_in_file_name(self): + """https://github.com/borgbackup/borg/issues/6063""" + def patched_setxattr_EACCES(*args, **kwargs): + raise OSError(errno.EACCES, 'EACCES') + + os.makedirs(os.path.join(self.input_path, 'dir%p')) + xattr.setxattr(b'input/dir%p', b'user.attribute', b'value') + self.cmd('init', self.repository_location, '-e' 'none') + self.cmd('create', self.repository_location + '::test', 'input') + with changedir('output'): + with patch.object(xattr, 'setxattr', patched_setxattr_EACCES): + self.cmd('extract', self.repository_location + '::test', exit_code=EXIT_WARNING) + @unittest.skipUnless('binary' in BORG_EXES, 'no borg.exe available') class ArchiverTestCaseBinary(ArchiverTestCase): From d9e923e66f1aa1c22e1fbea3cfc6065e5a341311 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Tue, 30 Nov 2021 19:41:49 +0300 Subject: [PATCH 2/2] Forward port #6064: avoid expanding path into LHS of formatting operation --- src/borg/testsuite/archiver.py | 2 -- src/borg/xattr.py | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index 09378e655..579224805 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -3460,7 +3460,6 @@ id: 2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02 assert 'Attic repository detected.' in output # derived from test_extract_xattrs_errors() - @pytest.mark.xfail(raises=ValueError, strict=True) @pytest.mark.skipif(not xattr.XATTR_FAKEROOT, reason='xattr not supported on this system or on this version of' 'fakeroot') def test_do_not_fail_when_percent_is_in_xattr_name(self): @@ -3477,7 +3476,6 @@ id: 2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02 self.cmd('extract', self.repository_location + '::test', exit_code=EXIT_WARNING) # derived from test_extract_xattrs_errors() - @pytest.mark.xfail(raises=ValueError, strict=True) @pytest.mark.skipif(not xattr.XATTR_FAKEROOT, reason='xattr not supported on this system or on this version of' 'fakeroot') def test_do_not_fail_when_percent_is_in_file_name(self): diff --git a/src/borg/xattr.py b/src/borg/xattr.py index a2039ebba..d34339370 100644 --- a/src/borg/xattr.py +++ b/src/borg/xattr.py @@ -132,7 +132,6 @@ 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: err_str = 'too big for this filesystem' elif e.errno == errno.ENOTSUP: @@ -146,5 +145,5 @@ def set_all(path, xattrs, follow_symlinks=False): # 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) + logger.warning('%s: when setting extended attribute %s: %s', path_str, k_str, err_str) return warning