From a42cd161de795443356f5e1076f1971b5f3af05f Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 24 Jan 2023 15:22:01 +0100 Subject: [PATCH 1/2] add test for extracted directory mtime --- src/borg/testsuite/archiver/extract_cmd.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/borg/testsuite/archiver/extract_cmd.py b/src/borg/testsuite/archiver/extract_cmd.py index 8412596a7..178178484 100644 --- a/src/borg/testsuite/archiver/extract_cmd.py +++ b/src/borg/testsuite/archiver/extract_cmd.py @@ -59,6 +59,20 @@ class ArchiverTestCase(ArchiverTestCaseBase): assert st1.st_ino == st2.st_ino assert st1.st_size == st2.st_size + @pytest.mark.skipif(not is_utime_fully_supported(), reason='cannot properly setup and execute test without utime') + def test_directory_timestamps(self): + self.create_test_files() + self.cmd('init', '--encryption=repokey', self.repository_location) + self.cmd('create', self.repository_location + '::test', 'input') + with changedir('output'): + self.cmd('extract', self.repository_location + '::test') + # extracting a file inside a directory touches the directory mtime + assert os.path.exists('output/input/dir2/file2') + # make sure borg fixes the directory mtime after touching it + sti = os.stat('input/dir2') + sto = os.stat('output/input/dir2') + assert sti.st_mtime_ns == sto.st_mtime_ns + @pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime") def test_atime(self): def has_noatime(some_file): From fdc48fdd1b68e8b7be0ad074a35a7efc15228cec Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 11 Feb 2023 00:42:30 +0100 Subject: [PATCH 2/2] more directory timestamp tests --- src/borg/testsuite/archiver/extract_cmd.py | 54 ++++++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/src/borg/testsuite/archiver/extract_cmd.py b/src/borg/testsuite/archiver/extract_cmd.py index 178178484..c5032b267 100644 --- a/src/borg/testsuite/archiver/extract_cmd.py +++ b/src/borg/testsuite/archiver/extract_cmd.py @@ -59,18 +59,54 @@ class ArchiverTestCase(ArchiverTestCaseBase): assert st1.st_ino == st2.st_ino assert st1.st_size == st2.st_size - @pytest.mark.skipif(not is_utime_fully_supported(), reason='cannot properly setup and execute test without utime') - def test_directory_timestamps(self): + @pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime") + def test_directory_timestamps1(self): self.create_test_files() - self.cmd('init', '--encryption=repokey', self.repository_location) - self.cmd('create', self.repository_location + '::test', 'input') - with changedir('output'): - self.cmd('extract', self.repository_location + '::test') + self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION) + + # default file archiving order (internal recursion) + self.cmd(f"--repo={self.repository_location}", "create", "test", "input") + with changedir("output"): + self.cmd(f"--repo={self.repository_location}", "extract", "test") # extracting a file inside a directory touches the directory mtime - assert os.path.exists('output/input/dir2/file2') + assert os.path.exists("output/input/dir2/file2") # make sure borg fixes the directory mtime after touching it - sti = os.stat('input/dir2') - sto = os.stat('output/input/dir2') + sti = os.stat("input/dir2") + sto = os.stat("output/input/dir2") + assert sti.st_mtime_ns == sto.st_mtime_ns + + @pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime") + def test_directory_timestamps2(self): + self.create_test_files() + self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION) + + # given order, dir first, file second + flist_dir_first = b"input/dir2\ninput/dir2/file2\n" + self.cmd(f"--repo={self.repository_location}", "create", "--paths-from-stdin", "test", input=flist_dir_first) + with changedir("output"): + self.cmd(f"--repo={self.repository_location}", "extract", "test") + # extracting a file inside a directory touches the directory mtime + assert os.path.exists("output/input/dir2/file2") + # make sure borg fixes the directory mtime after touching it + sti = os.stat("input/dir2") + sto = os.stat("output/input/dir2") + assert sti.st_mtime_ns == sto.st_mtime_ns + + @pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime") + def test_directory_timestamps3(self): + self.create_test_files() + self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION) + + # given order, file first, dir second + flist_file_first = b"input/dir2/file2\ninput/dir2\n" + self.cmd(f"--repo={self.repository_location}", "create", "--paths-from-stdin", "test", input=flist_file_first) + with changedir("output"): + self.cmd(f"--repo={self.repository_location}", "extract", "test") + # extracting a file inside a directory touches the directory mtime + assert os.path.exists("output/input/dir2/file2") + # make sure borg fixes the directory mtime after touching it + sti = os.stat("input/dir2") + sto = os.stat("output/input/dir2") assert sti.st_mtime_ns == sto.st_mtime_ns @pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime")