summaryrefslogtreecommitdiff
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-03-03 18:41:48 +0000
commitd5b80ee9e529f70bf8e24f2e2d9d6a5d6d00621a (patch)
tree1023b2e2593cca91c218a0ea176a7c3e0b0f65bd
parent8b162a4a651d35f1d2b5237983f896dae22ca7e4 (diff)
downloadmorph-d5b80ee9e529f70bf8e24f2e2d9d6a5d6d00621a.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.
-rw-r--r--morphlib/buildcommand.py23
-rw-r--r--morphlib/stagingarea.py22
2 files changed, 23 insertions, 22 deletions
diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py
index 8572450d..38057365 100644
--- a/morphlib/buildcommand.py
+++ b/morphlib/buildcommand.py
@@ -494,8 +494,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)
diff --git a/morphlib/stagingarea.py b/morphlib/stagingarea.py
index 991a1799..2c036085 100644
--- a/morphlib/stagingarea.py
+++ b/morphlib/stagingarea.py
@@ -187,29 +187,11 @@ class StagingArea(object):
'''
- chunk_cache_dir = os.path.join(self._app.settings['tempdir'], 'chunks')
- unpacked_artifact = os.path.join(
- chunk_cache_dir, os.path.basename(handle.name) + '.d')
- if not os.path.exists(unpacked_artifact):
- self._app.status(
- msg='Unpacking chunk from cache %(filename)s',
- filename=os.path.basename(handle.name))
- savedir = tempfile.mkdtemp(dir=chunk_cache_dir)
- try:
- morphlib.bins.unpack_binary_from_file(
- handle, savedir + '/')
- except BaseException, e: # pragma: no cover
- shutil.rmtree(savedir)
- 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(savedir, unpacked_artifact)
-
if not os.path.exists(self.dirname):
self._mkdir(self.dirname)
- self.hardlink_all_files(unpacked_artifact, self.dirname)
+ self.hardlink_all_files(artifact_checkout, self.dirname)
+ self.create_devices(artifact.source.morphology)
def remove(self):
'''Remove the entire staging area.