From b304a148f752e9f03678cd3a2568a64c08b62ad8 Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Tue, 3 Jun 2014 22:07:36 -0300 Subject: [PATCH] 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: Lucas Meneghel Rodrigues --- avocado/utils/archive.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/avocado/utils/archive.py b/avocado/utils/archive.py index 3e21eb91..9bebf7c1 100644 --- a/avocado/utils/archive.py +++ b/avocado/utils/archive.py @@ -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() -- GitLab