avocado.utils.archive: Warn of bad members inside archives

When performing tests with the latest LTP tarball, I found
a bad return from Tarfile().extract_file(), that could be
either a badly formed tarball or a Tarfile() bug. Either
way, the archive module was equipped to deal with such a
situation, not failing the test altogether.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 cba30b63
......@@ -26,11 +26,14 @@
"""
Library used to transparently uncompress compressed files.
"""
import logging
import os
import shutil
import tarfile
import zipfile
log = logging.getLogger('avocado.test')
class ArchiveException(Exception):
......@@ -172,14 +175,19 @@ class TarArchive(BaseArchive):
except (KeyError, AttributeError) as exc:
# Some corrupt tar files seem to produce this
# (specifically bad symlinks)
print("In the tar file %s the member %s is invalid: %s" %
(name, member.name, exc))
log.error("In the tar file %s the member %s is "
"invalid: %s" % (name, member.name, exc))
else:
dirname = os.path.dirname(filename)
if dirname and not os.path.exists(dirname):
os.makedirs(dirname)
with open(filename, 'wb') as outfile:
shutil.copyfileobj(extracted, outfile)
if extracted is not None:
shutil.copyfileobj(extracted, outfile)
else:
log.error("Member correspondent to file %s does "
"not seem to be a regular file or a link",
filename)
finally:
if extracted:
extracted.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册