diff --git a/CHANGELOG.md b/CHANGELOG.md index 56d5126..3e3aff2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Upcoming version +- Bugfix: Check the existence of a mirror while holding the mirror lock to no longer delete a mirror that was + created by a concurrent gitcache process. - Bugfix: Fetch the LFS objects of a `git checkout` of a tag or a commit as well. Previously, only a checkout of a branch triggered an LFS fetch of the mirror and the LFS objects of a tag or commit were downloaded by the git-lfs filters of the checkout itself. diff --git a/src/git_cache/git_mirror.py b/src/git_cache/git_mirror.py index 93d25e9..1eed233 100644 --- a/src/git_cache/git_mirror.py +++ b/src/git_cache/git_mirror.py @@ -166,10 +166,9 @@ def update(self, ref=None, force=False): Return: Returns True if the mirror was updated or False if the request timed out. """ - mirror_exists = self.database.get(self.path) is not None try: with Locker(f"Mirror {self.path}", self.lockfile, self.config): - if not mirror_exists: + if self.database.get(self.path) is None: rmtree(self.path, ignore_errors=True) if self._clone(ref): record_cache("miss_create", self.path) @@ -202,10 +201,9 @@ def ensure_exists(self, ref=None) -> bool: Return: Returns True if the mirror exists now or False if the request timed out. """ - mirror_exists = self.database.get(self.path) is not None try: with Locker(f"Mirror {self.path}", self.lockfile, self.config): - if not mirror_exists: + if self.database.get(self.path) is None: rmtree(self.path, ignore_errors=True) if self._clone(ref): record_cache("miss_create", self.path) @@ -227,10 +225,9 @@ def fetch(self, command_args: List[str]) -> bool: Return: Returns True if the command was successfull, otherwise False. """ - mirror_exists = self.database.get(self.path) is not None try: with Locker(f"Mirror {self.path}", self.lockfile, self.config): - if not mirror_exists: + if self.database.get(self.path) is None: LOG.error("Mirror does not exist!") return False return self._fetch(command_args)