From 59d3bf19201cabe85862dfa5bbaaa5898162357e Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Fri, 4 Nov 2011 10:22:20 -0500 Subject: VCS: Fix traceback when destination directory exists Signed-off-by: Sol Jerome --- src/lib/Client/Tools/VCS.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/lib/Client/Tools/VCS.py') diff --git a/src/lib/Client/Tools/VCS.py b/src/lib/Client/Tools/VCS.py index fa7748574..e6081dc1c 100644 --- a/src/lib/Client/Tools/VCS.py +++ b/src/lib/Client/Tools/VCS.py @@ -7,6 +7,7 @@ missing = [] import os +import shutil import sys # python-dulwich git imports try: @@ -62,6 +63,18 @@ class VCS(Bcfg2.Client.Tools.Tool): def Installgit(self, entry): """Checkout contents from a git repository""" destname = entry.get('name') + if os.path.lexists(destname): + # remove incorrect contents + try: + if os.path.isdir(destname): + shutil.rmtree(destname) + else: + os.remove(destname) + except OSError: + self.logger.info('Failed to remove %s' % \ + destname) + return False + destr = dulwich.repo.Repo.init(destname, mkdir=True) cl, host_path = dulwich.client.get_transport_and_path(entry.get('sourceurl')) remote_refs = cl.fetch(host_path, -- cgit v1.2.3-1-g7c22