Handle invalid tar layers and add tests
This commit is contained in:
parent
cc9d5798b3
commit
611bc895e1
2 changed files with 55 additions and 0 deletions
|
@ -1,6 +1,11 @@
|
|||
import os
|
||||
import tarfile
|
||||
|
||||
class TarLayerReadException(Exception):
|
||||
""" Exception raised when reading a layer has failed. """
|
||||
pass
|
||||
|
||||
|
||||
class TarLayerFormat(object):
|
||||
""" Class which creates a generator of the combined TAR data. """
|
||||
def __init__(self, tar_iterator):
|
||||
|
@ -10,9 +15,14 @@ class TarLayerFormat(object):
|
|||
for current_tar in self.tar_iterator():
|
||||
# Read the current TAR. If it is empty, we just continue
|
||||
# to the next one.
|
||||
tar_file = None
|
||||
try:
|
||||
tar_file = tarfile.open(mode='r|*', fileobj=current_tar)
|
||||
except tarfile.ReadError as re:
|
||||
if re.message != 'empty file':
|
||||
raise TarLayerReadException('Could not read layer')
|
||||
|
||||
if not tar_file:
|
||||
continue
|
||||
|
||||
# For each of the tar entries, yield them IF and ONLY IF we have not
|
||||
|
|
Reference in a new issue