Skip to content

Commit

Permalink
Merge pull request #42 from jpopelka/zip-not-graceful
Browse files Browse the repository at this point in the history
Don't upload archive to S3 if zipping fails.
  • Loading branch information
fridex authored Jun 7, 2017
2 parents 83531ef + 6a4861b commit 1a34381
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cucoslib/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 7 additions & 2 deletions cucoslib/storages/s3_mavenindex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from cucoslib.errors import TaskError
from cucoslib.process import Archive
from cucoslib.utils import tempdir
from . import AmazonS3
Expand All @@ -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"""
Expand Down
9 changes: 7 additions & 2 deletions cucoslib/storages/s3_owaspdepcheck.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from cucoslib.errors import TaskError
from cucoslib.process import Archive
from cucoslib.utils import tempdir
from . import AmazonS3
Expand All @@ -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):
Expand Down

0 comments on commit 1a34381

Please sign in to comment.