From 3d01b0b9da67abc62e7945bbb26fd54f94fb4c99 Mon Sep 17 00:00:00 2001 From: Arksine Date: Sun, 9 May 2021 14:53:56 -0400 Subject: [PATCH] update_manager: attempt to handle empty git objects Always run git fsck when initializing a repo. If a loose object error is detected when running git pull or git fetch, attempt to remove loose objects and retry. Signed-off-by: Eric Callahan --- moonraker/components/update_manager.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/moonraker/components/update_manager.py b/moonraker/components/update_manager.py index b975799..cc4b367 100644 --- a/moonraker/components/update_manager.py +++ b/moonraker/components/update_manager.py @@ -882,6 +882,7 @@ class GitRepo: if need_fetch: await self.fetch() + await self.run_fsck() self.upstream_url = await self.remote("get-url") self.current_commit = await self.rev_parse("HEAD") @@ -1100,6 +1101,10 @@ class GitRepo: branch = branch or f"{self.git_remote}/{self.git_branch}" await self._run_git_cmd(f"checkout {branch} -q") + async def run_fsck(self): + async with self.git_operation_lock: + await self._run_git_cmd("fsck --full", timeout=300., retries=1) + async def get_commits_behind(self): self._verify_repo() if self.is_current(): @@ -1265,6 +1270,14 @@ class GitRepo: if ret == 0: self.git_messages.clear() return + elif "loose object" in "\n".join(self.git_messages): + # attempt to remove corrupt objects + try: + await self.cmd_helper.run_cmd_with_response( + "find .git/objects/ -type f -empty | xargs rm", + timeout=10., retries=1, cwd=self.git_path) + except self.server.error: + pass retries -= 1 await tornado.gen.sleep(.5) self._check_lock_file_exists(remove=True)