From a604c67c3eec6df2a90882b2afd992d0d40a06e7 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 17 Nov 2015 10:46:22 -0700 Subject: [PATCH] fetch_repo(): Call rmtree() when all attempts fail Signed-off-by: Zack Cerza --- teuthology/repo_utils.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/teuthology/repo_utils.py b/teuthology/repo_utils.py index 5dd95e4adf..fe228a9951 100644 --- a/teuthology/repo_utils.py +++ b/teuthology/repo_utils.py @@ -6,7 +6,7 @@ import subprocess import time from .config import config -from .contextutil import safe_while +from .contextutil import safe_while, MaxWhileTries from .exceptions import BootstrapError, BranchNotFoundError, GitError log = logging.getLogger(__name__) @@ -178,17 +178,20 @@ def fetch_repo(url, branch, bootstrap=None, lock=True): lock_path = dest_path.rstrip('/') + '.lock' with FileLock(lock_path, noop=not lock): with safe_while(sleep=10, tries=60) as proceed: - while proceed(): - try: - enforce_repo_state(url, dest_path, - branch) - if bootstrap: - bootstrap(dest_path) - break - except GitError: - log.exception("Git error encountered; retrying") - except BootstrapError: - log.exception("Bootstrap error encountered; retrying") + try: + while proceed(): + try: + enforce_repo_state(url, dest_path, branch) + if bootstrap: + bootstrap(dest_path) + break + except GitError: + log.exception("Git error encountered; retrying") + except BootstrapError: + log.exception("Bootstrap error encountered; retrying") + except MaxWhileTries: + shutil.rmtree(dest_path, ignore_errors=True) + raise return dest_path -- 2.39.5