summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-04-28 08:51:23 +0000
committerBaserock Gerrit <gerrit@baserock.org>2015-04-28 14:35:04 +0000
commit2594f6d52878ef78d9809c52c7aebbe52434dba9 (patch)
tree40133b142f60b37650e3dec2b50a2507033054f9
parent154a760fb884cee14c2604b8bfbe52b0e7c0d4b1 (diff)
downloadmorph-2594f6d52878ef78d9809c52c7aebbe52434dba9.tar.gz
get-repo: Delete partially cloned repo on errors
If a `morph get-repo` command hits an error or is interrupted while the 'git clone' operation is in progress, the partial clone is left around. When the user tries to run the command again, they hit an error saying the directory already exists. Change-Id: Id4bb57f2136049ede0ea900e7e359255617427ec
-rw-r--r--morphlib/plugins/get_repo_plugin.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/morphlib/plugins/get_repo_plugin.py b/morphlib/plugins/get_repo_plugin.py
index 63e75237..5701de97 100644
--- a/morphlib/plugins/get_repo_plugin.py
+++ b/morphlib/plugins/get_repo_plugin.py
@@ -14,7 +14,9 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
+import logging
import os
+import shutil
import cliapp
@@ -106,8 +108,13 @@ class GetRepoPlugin(cliapp.Plugin):
cached_repo = lrc.get_updated_repo(chunk_spec['repo'],
chunk_spec['ref'])
- self._clone_repo(cached_repo, dirname,
- ref or chunk_spec['ref'])
+ try:
+ self._clone_repo(cached_repo, dirname,
+ ref or chunk_spec['ref'])
+ except BaseException as e:
+ logging.debug('Removing %s due to %s', dirname, e)
+ shutil.rmtree(dirname)
+ raise
else:
raise DirectoryAlreadyExistsError(chunk_spec['name'], dirname)