summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-04-09 18:19:16 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-04-09 18:19:16 +0100
commitaa47f79da62be1320c0b975edb55054b24448d7f (patch)
tree7fd0635d714f8967b5205410f8097b3ff533d6a7
parentcc9d92874c159b65b248f8f8f7e164aa32416836 (diff)
downloadmorph-aa47f79da62be1320c0b975edb55054b24448d7f.tar.gz
Remove downloaded bundle after it has been cloned
-rw-r--r--morphlib/localrepocache.py10
-rw-r--r--morphlib/localrepocache_tests.py6
2 files changed, 16 insertions, 0 deletions
diff --git a/morphlib/localrepocache.py b/morphlib/localrepocache.py
index 9beba4af..c6ede082 100644
--- a/morphlib/localrepocache.py
+++ b/morphlib/localrepocache.py
@@ -117,6 +117,15 @@ class LocalRepoCache(object):
source_handle.close()
target_handle.close()
+ def _remove(self, filename): # pragma: no cover
+ '''Remove given file.
+
+ This method is meant to be overridden by unit tests.
+
+ '''
+
+ os.remove(filename)
+
def _escape(self, url):
'''Escape a URL so it can be used as a basename in a file.'''
@@ -152,6 +161,7 @@ class LocalRepoCache(object):
bundle_path = path + '.bundle'
if self._fetch(bundle_url, bundle_path):
self._git(['clone', bundle_path, path])
+ self._remove(bundle_path)
return True
else:
return False
diff --git a/morphlib/localrepocache_tests.py b/morphlib/localrepocache_tests.py
index add0aa20..66a0a3e5 100644
--- a/morphlib/localrepocache_tests.py
+++ b/morphlib/localrepocache_tests.py
@@ -33,12 +33,14 @@ class LocalRepoCacheTests(unittest.TestCase):
self.cache = set()
self.remotes = []
self.fetched = []
+ self.removed = []
self.lrc = morphlib.localrepocache.LocalRepoCache(self.cachedir,
baseurls,
bundle_base_url)
self.lrc._git = self.fake_git
self.lrc._exists = self.fake_exists
self.lrc._fetch = self.not_found
+ self.lrc._remove = self.fake_remove
def fake_git(self, args):
if args[0] == 'clone':
@@ -55,6 +57,9 @@ class LocalRepoCacheTests(unittest.TestCase):
def fake_exists(self, filename):
return filename in self.cache
+ def fake_remove(self, filename):
+ self.removed.append(filename)
+
def not_found(self, url, path):
return False
@@ -98,6 +103,7 @@ class LocalRepoCacheTests(unittest.TestCase):
self.lrc.cache_repo(self.repourl)
self.assertEqual(self.fetched, [self.bundle_url])
self.assertEqual(self.remotes, [self.cache_path + '.bundle'])
+ self.assertEqual(self.removed, [self.cache_path + '.bundle'])
def test_gets_cached_relative_repo(self):
self.lrc.cache_repo(self.reponame)