summaryrefslogtreecommitdiff
path: root/morphlib/buildcommand.py
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2015-03-03 13:00:40 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2015-04-10 13:52:25 +0000
commit5847e6ec39dd4f62bcbf819f9bef65316ea6933a (patch)
treeff2c9a20ea4fbde2e242e4bf0a7deed13a16910e /morphlib/buildcommand.py
parentfff08941639fc02254f1ec93b675e596d3037651 (diff)
downloadmorph-5847e6ec39dd4f62bcbf819f9bef65316ea6933a.tar.gz
Move the chunk cache logic into buildcommand
This avoids needing to pass the cache to the staging area since lac.get returns a path to a directory tree rather than a file handle now, so we also don't need to do any unpacking.
Diffstat (limited to 'morphlib/buildcommand.py')
-rw-r--r--morphlib/buildcommand.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py
index fd5acdf5..d7c445df 100644
--- a/morphlib/buildcommand.py
+++ b/morphlib/buildcommand.py
@@ -497,8 +497,27 @@ class BuildCommand(object):
chunk_name=artifact.name,
cache=artifact.source.cache_key[:7],
chatty=True)
- handle = self.lac.get(artifact)
- staging_area.install_artifact(handle)
+ chunk_cache_dir = os.path.join(self.app.settings['tempdir'],
+ 'chunks')
+ artifact_checkout = os.path.join(
+ chunk_cache_dir, os.path.basename(artifact.basename()) + '.d')
+ if not os.path.exists(artifact_checkout):
+ self.app.status(
+ msg='Checking out %(chunk)s from cache.',
+ chunk=artifact.name
+ )
+ temp_checkout = os.path.join(self.app.settings['tempdir'],
+ artifact.basename())
+ try:
+ self.lac.get(artifact, temp_checkout)
+ except BaseException:
+ shutil.rmtree(temp_checkout)
+ raise
+ # TODO: This rename is not concurrency safe if two builds are
+ # extracting the same chunk, one build will fail because
+ # the other renamed its tempdir here first.
+ os.rename(temp_checkout, artifact_checkout)
+ staging_area.install_artifact(artifact, artifact_checkout)
if target_source.build_mode == 'staging':
morphlib.builder.ldconfig(self.app.runcmd, staging_area.dirname)