From 65ee2f821c8c642aae60f462ff8f209ebdc93e20 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Thu, 19 Mar 2015 12:38:11 +0000 Subject: Morph build 11ac5b237b3640718da94ad8e252d330 System branch: master --- morphlib/buildcommand.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'morphlib/buildcommand.py') diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index be8a1507..c83abca6 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -418,8 +418,10 @@ class BuildCommand(object): # module into morphlib.remoteartififactcache first. to_fetch = [] if not self.lac.has(artifact): - to_fetch.append((self.rac.get(artifact), - self.lac.put(artifact))) + self.app.status( + msg='Fetching to local cache: artifact %(name)s', + name=artifact.name) + self.lac.copy_from_remote(artifact, self.rac) if artifact.source.morphology.needs_artifact_metadata_cached: if not self.lac.has_artifact_metadata(artifact, 'meta'): @@ -428,9 +430,6 @@ class BuildCommand(object): self.lac.put_artifact_metadata(artifact, 'meta'))) if len(to_fetch) > 0: - self.app.status( - msg='Fetching to local cache: artifact %(name)s', - name=artifact.name) fetch_files(to_fetch) def create_staging_area(self, build_env, use_chroot=True, extra_env={}, @@ -493,8 +492,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) -- cgit v1.2.1