@@ -143,6 +143,57 @@ def test_import_tar_gz(self, tar_format="GNU"):
143143 self .cmd (f"--repo={ self .repository_location } " , "extract" , "dst" )
144144 self .assert_dirs_equal ("input" , "output/input" , ignore_ns = True , ignore_xattrs = True )
145145
146+ @requires_gnutar
147+ def test_import_concatenated_tar_with_ignore_zeros (self ):
148+ self .create_test_files (create_hardlinks = False ) # hardlinks become separate files
149+ os .unlink ("input/flagfile" )
150+ with changedir ("input" ):
151+ subprocess .check_call (["tar" , "cf" , "file1.tar" , "file1" ])
152+ subprocess .check_call (["tar" , "cf" , "the_rest.tar" , "--exclude" , "file1*" , "." ])
153+ with open ("concatenated.tar" , "wb" ) as concatenated :
154+ with open ("file1.tar" , "rb" ) as file1 :
155+ concatenated .write (file1 .read ())
156+ # Clean up for assert_dirs_equal.
157+ os .unlink ("file1.tar" )
158+
159+ with open ("the_rest.tar" , "rb" ) as the_rest :
160+ concatenated .write (the_rest .read ())
161+ # Clean up for assert_dirs_equal.
162+ os .unlink ("the_rest.tar" )
163+
164+ self .cmd (f"--repo={ self .repository_location } " , "rcreate" , "--encryption=none" )
165+ self .cmd (f"--repo={ self .repository_location } " , "import-tar" , "--ignore-zeros" , "dst" , "input/concatenated.tar" )
166+ # Clean up for assert_dirs_equal.
167+ os .unlink ("input/concatenated.tar" )
168+
169+ with changedir (self .output_path ):
170+ self .cmd (f"--repo={ self .repository_location } " , "extract" , "dst" )
171+ self .assert_dirs_equal ("input" , "output" , ignore_ns = True , ignore_xattrs = True )
172+
173+ @requires_gnutar
174+ def test_import_concatenated_tar_without_ignore_zeros (self ):
175+ self .create_test_files (create_hardlinks = False ) # hardlinks become separate files
176+ os .unlink ("input/flagfile" )
177+ with changedir ("input" ):
178+ subprocess .check_call (["tar" , "cf" , "file1.tar" , "file1" ])
179+ subprocess .check_call (["tar" , "cf" , "the_rest.tar" , "--exclude" , "file1*" , "." ])
180+ with open ("concatenated.tar" , "wb" ) as concatenated :
181+ with open ("file1.tar" , "rb" ) as file1 :
182+ concatenated .write (file1 .read ())
183+ with open ("the_rest.tar" , "rb" ) as the_rest :
184+ concatenated .write (the_rest .read ())
185+ os .unlink ("the_rest.tar" )
186+
187+ self .cmd (f"--repo={ self .repository_location } " , "rcreate" , "--encryption=none" )
188+ self .cmd (f"--repo={ self .repository_location } " , "import-tar" , "dst" , "input/concatenated.tar" )
189+
190+ with changedir (self .output_path ):
191+ self .cmd (f"--repo={ self .repository_location } " , "extract" , "dst" )
192+
193+ # Negative test -- assert that only file1 has been extracted, and the_rest has been ignored
194+ # due to zero-filled block marker.
195+ self .assert_equal (os .listdir ("output" ), ["file1" ])
196+
146197 def test_roundtrip_pax_borg (self ):
147198 self .create_test_files ()
148199 self .cmd (f"--repo={ self .repository_location } " , "rcreate" , "--encryption=none" )
0 commit comments