浏览代码

use "fail" chunker to test erroneous input file skipping

if a file can't be read (like here: there is a simulated
I/O error in the 2nd chunk of file2), it should be logged
with "E" status, skipped and backup shall proceed with
next file(s).

also, check that the repo has no orphan chunks (exception
handling code needs to deal with 1st chunk of file2 which
already has been written / incref'd in the repo).
Thomas Waldmann 2 年之前
父节点
当前提交
11fd6afb0f
共有 1 个文件被更改,包括 26 次插入0 次删除
  1. 26 0
      src/borg/testsuite/archiver/create_cmd.py

+ 26 - 0
src/borg/testsuite/archiver/create_cmd.py

@@ -191,6 +191,32 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         out = self.cmd(f"--repo={self.repository_location}", "extract", "test", "stdin", "--stdout", binary_output=True)
         assert out == input_data
 
+    def test_create_erroneous_file(self):
+        chunk_size = 1000  # fixed chunker with this size, also volume based checkpointing after that volume
+        self.create_regular_file(os.path.join(self.input_path, "file1"), size=chunk_size * 2)
+        self.create_regular_file(os.path.join(self.input_path, "file2"), size=chunk_size * 2)
+        self.create_regular_file(os.path.join(self.input_path, "file3"), size=chunk_size * 2)
+        self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
+        flist = "".join(f"input/file{n}\n" for n in range(1, 4))
+        out = self.cmd(
+            f"--repo={self.repository_location}",
+            "create",
+            f"--chunker-params=fail,{chunk_size},RRRERRR",
+            "--paths-from-stdin",
+            "--list",
+            "test",
+            input=flist.encode(),
+            exit_code=1,
+        )
+        assert "E input/file2" in out
+        # repo looking good overall? checks for rc == 0.
+        self.cmd(f"--repo={self.repository_location}", "check", "--debug")
+        # check files in created archive
+        out = self.cmd(f"--repo={self.repository_location}", "list", "test")
+        assert "input/file1" in out
+        assert "input/file2" not in out
+        assert "input/file3" in out
+
     def test_create_content_from_command(self):
         self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
         input_data = "some test content"