From 6a4861b569c3f52ef04d87f18c96497581a47152 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Wed, 7 Jun 2017 16:49:38 +0200 Subject: [PATCH] Don't upload archive to S3 if zipping fails. --- cucoslib/process.py | 2 +- cucoslib/storages/s3_mavenindex.py | 9 +++++++-- cucoslib/storages/s3_owaspdepcheck.py | 9 +++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cucoslib/process.py b/cucoslib/process.py index 2772492ec..d89e9fc71 100644 --- a/cucoslib/process.py +++ b/cucoslib/process.py @@ -155,7 +155,7 @@ def zip_file(file, archive, junk_paths=False): # Store just the name of a saved file (junk the path), not directory names. # By default, zip will store the full path (relative to the current directory). command.extend(['--junk-paths']) - TimedCommand.get_command_output(command) + TimedCommand.get_command_output(command, graceful=False) @staticmethod def extract_zip(target, dest, mkdest=False): diff --git a/cucoslib/storages/s3_mavenindex.py b/cucoslib/storages/s3_mavenindex.py index 63ca9bf49..804fcd5c5 100644 --- a/cucoslib/storages/s3_mavenindex.py +++ b/cucoslib/storages/s3_mavenindex.py @@ -1,4 +1,5 @@ import os +from cucoslib.errors import TaskError from cucoslib.process import Archive from cucoslib.utils import tempdir from . import AmazonS3 @@ -13,8 +14,12 @@ def store_index(self, target_dir): with tempdir() as temp_dir: central_index_dir = os.path.join(target_dir, self._INDEX_DIRNAME) archive_path = os.path.join(temp_dir, self._INDEX_ARCHIVE) - Archive.zip_file(central_index_dir, archive_path, junk_paths=True) - self.store_file(archive_path, self._INDEX_ARCHIVE) + try: + Archive.zip_file(central_index_dir, archive_path, junk_paths=True) + except TaskError: + pass + else: + self.store_file(archive_path, self._INDEX_ARCHIVE) def retrieve_index_if_exists(self, target_dir): """ Retrieve central-index.zip from S3 and extract into target_dir/central-index""" diff --git a/cucoslib/storages/s3_owaspdepcheck.py b/cucoslib/storages/s3_owaspdepcheck.py index b7e3e0773..8eec3d220 100644 --- a/cucoslib/storages/s3_owaspdepcheck.py +++ b/cucoslib/storages/s3_owaspdepcheck.py @@ -1,4 +1,5 @@ import os +from cucoslib.errors import TaskError from cucoslib.process import Archive from cucoslib.utils import tempdir from . import AmazonS3 @@ -13,8 +14,12 @@ def store_depcheck_db(self, data_dir): with tempdir() as archive_dir: archive_path = os.path.join(archive_dir, self._DB_ARCHIVE) db_file_path = os.path.join(data_dir, self._DB_FILENAME) - Archive.zip_file(db_file_path, archive_path, junk_paths=True) - self.store_file(archive_path, self._DB_ARCHIVE) + try: + Archive.zip_file(db_file_path, archive_path, junk_paths=True) + except TaskError: + pass + else: + self.store_file(archive_path, self._DB_ARCHIVE) def store_depcheck_db_if_not_exists(self, data_dir): if not self.object_exists(self._DB_ARCHIVE):