From 58c0a0186f72f02d966b56e6264de33cc065f56b Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 2 Jan 2021 22:42:45 +0100 Subject: [PATCH] add a test for hardlink extraction issue, see #5603 --- src/borg/testsuite/archiver.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index fbe5931ab..c29857931 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -857,6 +857,29 @@ class ArchiverTestCase(ArchiverTestCaseBase): assert os.stat('input/dir1/aaaa').st_nlink == 2 assert os.stat('input/dir1/source2').st_nlink == 2 + @requires_hardlinks + def test_extract_hardlinks_twice(self): + # setup for #5603 + path_a = os.path.join(self.input_path, 'a') + path_b = os.path.join(self.input_path, 'b') + os.mkdir(path_a) + os.mkdir(path_b) + hl_a = os.path.join(path_a, 'hardlink') + hl_b = os.path.join(path_b, 'hardlink') + self.create_regular_file(hl_a, contents=b'123456') + os.link(hl_a, hl_b) + self.cmd('init', '--encryption=none', self.repository_location) + self.cmd('create', self.repository_location + '::test', 'input', 'input') # give input twice! + # now test extraction + with changedir('output'): + self.cmd('extract', self.repository_location + '::test') + # if issue #5603 happens, extraction gives rc == 1 (triggering AssertionError) and warnings like: + # input/a/hardlink: link: [Errno 2] No such file or directory: 'input/a/hardlink' -> 'input/a/hardlink' + # input/b/hardlink: link: [Errno 2] No such file or directory: 'input/a/hardlink' -> 'input/b/hardlink' + # otherwise, when fixed, the hardlinks should be there and have a link count of 2 + assert os.stat('input/a/hardlink').st_nlink == 2 + assert os.stat('input/b/hardlink').st_nlink == 2 + def test_extract_include_exclude(self): self.cmd('init', '--encryption=repokey', self.repository_location) self.create_regular_file('file1', size=1024 * 80)