From cf80cc5afe9586291510e74cc2f53bed6085bd17 Mon Sep 17 00:00:00 2001 From: Mark Edgington Date: Tue, 2 May 2017 13:29:52 -0400 Subject: [PATCH 1/2] add test for preserved intermediate folder permissions This tests whether the permissions metadata is preserved when a folder is excluded but still recursed into to find a matching file in a subfolder. --- src/borg/testsuite/archiver.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index 3aa2c1b5cb..0efc6f679d 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -960,6 +960,31 @@ def test_create_pattern_exclude_folder_no_recurse(self): self.assert_not_in('input/x/a', output) self.assert_in('A input/y/foo_y', output) + def test_create_pattern_intermediate_folder_permissions(self): + """test for correct metadata when patterns exclude a parent folder but include a child""" + self.patterns_file_path2 = os.path.join(self.tmpdir, 'patterns2') + with open(self.patterns_file_path2, 'wb') as fd: + fd.write(b'+ input/x/a\n+ input/x/b\n- input/x*\n') + + self.cmd('init', '--encryption=repokey', self.repository_location) + + self.create_regular_file('x/a/foo_a', size=1024 * 80) + self.create_regular_file('x/b/foo_b', size=1024 * 80) + with changedir('input'): + os.chmod('x/a', 0o750) + os.chmod('x/b', 0o700) + self.cmd('create', '--patterns-from=' + self.patterns_file_path2, + self.repository_location + '::test', '.') + + # extract the archive and verify that the "intermediate" folder + # permissions have been preserved. + with changedir('output'): + self.cmd('extract', self.repository_location + '::test') + + for fname, mode in [('x/a', 0o750), ('x/b', 0o700)]: + st = os.stat(fname) + self.assert_equal(st.st_mode & 0o777, mode) + def test_extract_pattern_opt(self): self.cmd('init', '--encryption=repokey', self.repository_location) self.create_regular_file('file1', size=1024 * 80) From eb51c3c0c64c28d49550fb869c58f6741edbfb1c Mon Sep 17 00:00:00 2001 From: Mark Edgington Date: Sat, 20 May 2017 16:06:46 -0400 Subject: [PATCH 2/2] add test for correct order of intermediate folders Removed last test, and replaced with simpler test to verify that an intermediate folder is included in the archive prior to its contents when a folder is excluded but still recursed into to find a matching file in a subfolder. --- src/borg/testsuite/archiver.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index 0efc6f679d..af372356ae 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -960,8 +960,8 @@ def test_create_pattern_exclude_folder_no_recurse(self): self.assert_not_in('input/x/a', output) self.assert_in('A input/y/foo_y', output) - def test_create_pattern_intermediate_folder_permissions(self): - """test for correct metadata when patterns exclude a parent folder but include a child""" + def test_create_pattern_intermediate_folders_first(self): + """test that intermediate folders appear first when patterns exclude a parent folder but include a child""" self.patterns_file_path2 = os.path.join(self.tmpdir, 'patterns2') with open(self.patterns_file_path2, 'wb') as fd: fd.write(b'+ input/x/a\n+ input/x/b\n- input/x*\n') @@ -971,19 +971,19 @@ def test_create_pattern_intermediate_folder_permissions(self): self.create_regular_file('x/a/foo_a', size=1024 * 80) self.create_regular_file('x/b/foo_b', size=1024 * 80) with changedir('input'): - os.chmod('x/a', 0o750) - os.chmod('x/b', 0o700) self.cmd('create', '--patterns-from=' + self.patterns_file_path2, self.repository_location + '::test', '.') - # extract the archive and verify that the "intermediate" folder - # permissions have been preserved. - with changedir('output'): - self.cmd('extract', self.repository_location + '::test') + # list the archive and verify that the "intermediate" folders appear before + # their contents + out = self.cmd('list', '--format', '{type} {path}{NL}', self.repository_location + '::test') + out_list = out.splitlines() + + self.assert_in('d x/a', out_list) + self.assert_in('d x/b', out_list) - for fname, mode in [('x/a', 0o750), ('x/b', 0o700)]: - st = os.stat(fname) - self.assert_equal(st.st_mode & 0o777, mode) + assert out_list.index('d x/a') < out_list.index('- x/a/foo_a') + assert out_list.index('d x/b') < out_list.index('- x/b/foo_b') def test_extract_pattern_opt(self): self.cmd('init', '--encryption=repokey', self.repository_location)