浏览代码

more directory timestamp tests

Thomas Waldmann 2 年之前
父节点
当前提交
fdc48fdd1b
共有 1 个文件被更改,包括 45 次插入9 次删除
  1. 45 9
      src/borg/testsuite/archiver/extract_cmd.py

+ 45 - 9
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(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")
+        # 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_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('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)
+
+        # 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')
+        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")