guard invocations of tar from interactive mode
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 30 Jan 2020 09:41:31 +0000 (10:41 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Sat, 1 Feb 2020 13:42:43 +0000 (14:42 +0100)
On failure, tests may cause GNU tar to prompt for user input like
for example volume names etc. which may interrupt the test run.
Prevent that by passing /dev/null wherever we shell out to tar.

deltatar/tarfile.py
testing/__init__.py
testing/test_encryption.py
testing/test_multivol.py

index edfe584..b4b784a 100644 (file)
@@ -2787,6 +2787,7 @@ class TarFile(object):
             self._extfileobj = True
             self._dbg(3, 'open_volume: using external fileobj {}', fileobj)
         self.name = os.path.abspath(name) if name else None
+        self.fileobj.close()
         self.fileobj = fileobj
 
         # init data structures
index 8f3bbbe..ebaf6c8 100644 (file)
@@ -29,7 +29,6 @@ def new_volume_handler(tarobj, base_name, volume_number, encryption=None):
     Handles the new volumes
     '''
     volume_path = "%s.%d" % (base_name, volume_number)
-    tarobj.close()
     tarobj.open_volume(volume_path, encryption=encryption)
 
 def make_new_encryption_volume_handler(encryption):
index 26e62e0..fee7b41 100644 (file)
@@ -81,7 +81,7 @@ class EncryptionTest(BaseTest):
 
         # extract with normal tar and check output
         os.system("zcat sample.tar.gz 2>/dev/null > sample.tar")
-        os.system("tar xf sample.tar")
+        os.system("tar xf sample.tar </dev/null")
         assert os.path.exists("big")
         assert hash == self.md5sum("big")
 
@@ -121,7 +121,7 @@ class EncryptionTest(BaseTest):
 
         # extract with normal tar and check output
         os.system("zcat sample.tar.gz 2>/dev/null > sample.tar")
-        os.system("tar xf sample.tar")
+        os.system("tar xf sample.tar </dev/null")
         assert os.path.exists("big")
         assert hash == self.md5sum("big")
 
@@ -161,7 +161,7 @@ class EncryptionTest(BaseTest):
 
         # extract with normal tar and check output
         os.system("zcat sample.tar.gz 2>/dev/null > sample.tar")
-        os.system("tar xf sample.tar")
+        os.system("tar xf sample.tar </dev/null")
         assert os.path.exists("big")
         assert hash == self.md5sum("big")
 
@@ -249,7 +249,7 @@ class EncryptionTest(BaseTest):
             fname = "pdtcrypt-object-%d.bin" % (i + 1)
             assert os.path.exists(fname)
             os.system("zcat '%s' 2>/dev/null > sample.tar" % fname)
-            os.system("tar xf sample.tar")
+            os.system("tar xf sample.tar </dev/null")
 
         for fname, digest in hash.items():
             assert os.path.exists(fname)
@@ -298,7 +298,7 @@ class EncryptionTest(BaseTest):
             fname = "pdtcrypt-object-%d.bin" % (i + 1)
             assert os.path.exists(fname)
             os.system("zcat '%s' 2>/dev/null > sample.tar" % fname)
-            os.system("tar xf sample.tar")
+            os.system("tar xf sample.tar </dev/null")
 
         for fname, digest in hash.items():
             assert os.path.exists(fname)
index 1f8cecb..580ec97 100644 (file)
@@ -69,7 +69,7 @@ class MultivolGnuFormatTest(BaseTest):
         assert not os.path.exists("big")
 
         # extract and check
-        os.system("tar xfM sample.tar")
+        os.system("tar xfM sample.tar </dev/null")
         assert os.path.exists("big")
         assert hash == self.md5sum("big")
 
@@ -99,7 +99,7 @@ class MultivolGnuFormatTest(BaseTest):
         assert not os.path.exists("big")
 
         # extract with normal tar and check output
-        os.system("tar xfM sample.tar --file=sample.tar.1")
+        os.system("tar xfM sample.tar --file=sample.tar.1 </dev/null")
         assert os.path.exists("big")
         assert hash == self.md5sum("big")
 
@@ -130,7 +130,7 @@ class MultivolGnuFormatTest(BaseTest):
         assert not os.path.exists("big")
 
         # extract with normal tar and check output
-        os.system("tar xfM sample.tar --file=sample.tar.1 --file=sample.tar.2")
+        os.system("tar xfM sample.tar --file=sample.tar.1 --file=sample.tar.2 </dev/null")
         assert os.path.exists("big")
         assert hash == self.md5sum("big")
 
@@ -167,7 +167,7 @@ class MultivolGnuFormatTest(BaseTest):
         os.unlink("small2")
 
         # extract with normal tar and check output
-        os.system("tar xfM sample.tar --file=sample.tar.1 --file=sample.tar.2")
+        os.system("tar xfM sample.tar --file=sample.tar.1 --file=sample.tar.2 </dev/null")
         for key, value in hash.items():
             assert os.path.exists(key)
             assert value == self.md5sum(key)
@@ -388,7 +388,7 @@ class MultivolGnuFormatTest(BaseTest):
 
         # create the tar file with volumes
         os.system("tar cM --format=%s -L 3000 big --file=sample.tar "\
-            "--file=sample.tar.1" % self.tar_command_format)
+            "--file=sample.tar.1 </dev/null" % self.tar_command_format)
 
         # check that the tar volumes were correctly created
         assert os.path.exists("sample.tar")
@@ -420,7 +420,7 @@ class MultivolGnuFormatTest(BaseTest):
 
         # create the tar file with volumes
         os.system("tar cM --format=%s -L 3000 big small small2 --file=sample.tar "\
-            "--file=sample.tar.1" % self.tar_command_format)
+            "--file=sample.tar.1 </dev/null" % self.tar_command_format)
 
         # check that the tar volumes were correctly created
         assert os.path.exists("sample.tar")