From 2fdbe7308726e3335838c46ae6d703231215d60a Mon Sep 17 00:00:00 2001 From: hudeng Date: Tue, 9 Apr 2024 14:37:03 +0800 Subject: [PATCH] fix: cache lock file not deleted in an abnormal state, resulting in other tasks not blocking --- TarSCM/scm/base.py | 55 ++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/TarSCM/scm/base.py b/TarSCM/scm/base.py index 52fd92cf..1956eeea 100644 --- a/TarSCM/scm/base.py +++ b/TarSCM/scm/base.py @@ -146,37 +146,40 @@ def fetch_upstream(self): self._calc_dir_to_clone_to(clone_prefix) self.prepare_clone_dir() - self.lock_cache() - - if not os.path.isdir(self.clone_dir): - # initial clone - logging.debug( - "[fetch_upstream] Initial checkout/clone to directory: '%s'", - self.clone_dir - ) - os.mkdir(self.clone_dir) - self.fetch_upstream_scm() - else: - logging.info("Detected cached repository...") - self.update_cache() + try: + self.lock_cache() + + if not os.path.isdir(self.clone_dir): + # initial clone + logging.debug( + "[fetch_upstream] Initial checkout/clone to directory: '%s'", + self.clone_dir + ) + os.mkdir(self.clone_dir) + self.fetch_upstream_scm() + else: + logging.info("Detected cached repository...") + self.update_cache() - self.prepare_working_copy() + self.prepare_working_copy() - # switch_to_revision - self.switch_revision() + # switch_to_revision + self.switch_revision() - # git specific: after switching to desired revision its necessary to - # update - # submodules since they depend on the actual version of the selected - # revision - self.fetch_submodules() + # git specific: after switching to desired revision its necessary to + # update + # submodules since they depend on the actual version of the selected + # revision + self.fetch_submodules() - # obs_scm specific: do not allow running git-lfs to prevent storage - # duplication with tar_scm - if self.args.use_obs_scm: - self.fetch_lfs() + # obs_scm specific: do not allow running git-lfs to prevent storage + # duplication with tar_scm + if self.args.use_obs_scm: + self.fetch_lfs() - self.unlock_cache() + self.unlock_cache() + finally: + self.unlock_cache() def fetch_submodules(self): """NOOP in other scm's than git"""