[PATCH] Make ccache use the same directory for repos that are clones

Jonathan Maw jonathan.maw at codethink.co.uk
Thu Jan 3 17:30:45 GMT 2013


This patch makes morph store its ccaches by the url's basename instead
of using the whole url. This fixes the problem of morph choking when it
tries to mount a directory with a colon in its path, and also makes
all clones of one repository use the same cache (probably). This will
cause projects with the same name to use the same cache, but that is
not likely to cause serious problems.
---
 morphlib/builder2.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 0c1acfd..a60c4a4 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012  Codethink Limited
+# Copyright (C) 2012-2013  Codethink Limited
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@ import traceback
 import subprocess
 import tempfile
 import gzip
+from urlparse import urlparse
 
 import cliapp
 
@@ -294,9 +295,19 @@ class ChunkBuilder(BuilderBase):
         if not os.path.isdir(ccache_dir):
             os.makedirs(ccache_dir)
         # Get a path for the repo's ccache
-        ccache_repobase = os.path.basename(self.artifact.source.repo.path)
-        ccache_repodir = os.path.join(ccache_dir,
-                                      ccache_repobase)
+        ccache_url = self.artifact.source.repo.url
+        ccache_path = urlparse(ccache_url).path
+        ccache_repobase = os.path.basename(ccache_path)
+        if ':' in ccache_repobase: # the basename is a repo-alias
+            resolver = morphlib.repoaliasresolver.RepoAliasResolver(
+                self.app.settings['repo-alias'])
+            ccache_url = resolver.pull_url(ccache_repobase)
+            ccache_path = urlparse(ccache_url).path
+            ccache_repobase = os.path.basename(ccache_path)
+        if ccache_repobase.endswith('.git'):
+            ccache_repobase = ccache_repobase[:-len('.git')]
+
+        ccache_repodir = os.path.join(ccache_dir, ccache_repobase)
         # Make sure that directory exists
         if not os.path.isdir(ccache_repodir):
             os.mkdir(ccache_repodir)
-- 
1.7.11.7





More information about the baserock-dev mailing list