From 5847e6ec39dd4f62bcbf819f9bef65316ea6933a Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Tue, 3 Mar 2015 13:00:40 +0000 Subject: 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. --- morphlib/buildcommand.py | 23 +++++++++++++++++++++-- morphlib/stagingarea.py | 23 ++--------------------- 2 files changed, 23 insertions(+), 23 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) diff --git a/morphlib/stagingarea.py b/morphlib/stagingarea.py index 28b22031..768ec643 100644 --- a/morphlib/stagingarea.py +++ b/morphlib/stagingarea.py @@ -185,30 +185,11 @@ class StagingArea(object): the artifact is a tarball. ''' - - 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 as 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. -- cgit v1.2.1