Skip to content

Commit

Permalink
Delete cache if the bundle operation did not succeed. (#204)
Browse files Browse the repository at this point in the history
* Delete cache if the bundle operation did not succeed.
For bundle v2, only use cache if the previous bundling succeeded.

Signed-off-by: Zachary Michaels <zacmicha@amazon.com>
  • Loading branch information
zmichaels11 authored Dec 14, 2020
1 parent 0042304 commit 0dc18ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions colcon_bundle/verb/_archive_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def generate_archive_v2(path_context: PathContext,

logger.info('Archiving complete')
print('Archiving complete!')
_mark_cache_valid(path_context)


def _mark_cache_valid(path_context):
cache_valid_file = path_context.cache_valid_path()
with open(cache_valid_file, 'a'):
os.utime(cache_valid_file)


def recursive_tar_in_path(tar_path, path):
Expand Down
10 changes: 10 additions & 0 deletions colcon_bundle/verb/_path_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from pathlib import Path
import shutil

from colcon_bundle.verb import check_and_mark_bundle_tool, \
check_and_mark_bundle_version, \
Expand Down Expand Up @@ -47,6 +48,11 @@ def __init__(self,
self._bundle_cache = self._bundle_base
if cache_version == 2:
self._bundle_cache = os.path.join(self._bundle_base, 'cache')
if os.path.exists(self.cache_valid_path()):
os.remove(self.cache_valid_path())
elif os.path.exists(self._bundle_cache):
print('Cache is not valid. Clearing cache...')
shutil.rmtree(self._bundle_cache)
os.makedirs(self._bundle_cache, exist_ok=True)
self._install_base = install_base

Expand Down Expand Up @@ -125,3 +131,7 @@ def bundle_v2_output_path(self): # noqa: D400
def sources_tar_gz_path(self): # noqa: D400
""":return: File path for sources files tarball"""
return os.path.join(self._bundle_base, 'sources.tar.gz')

def cache_valid_path(self): # noqa: D400
""":return: File path for cache valid file."""
return os.path.join(self._bundle_cache, '.valid')

0 comments on commit 0dc18ce

Please sign in to comment.