Skip to content

Commit

Permalink
git_deploy: limit corruption detection
Browse files Browse the repository at this point in the history
Signed-off-by:  Eric Callahan <[email protected]>
  • Loading branch information
Arksine committed May 28, 2024
1 parent 3b1c21a commit 7f89bd7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions moonraker/components/update_manager/git_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ async def _check_repo_status(self) -> bool:
self.git_messages.clear()
try:
cmd = "status --porcelain -b"
resp = await self._run_git_cmd(cmd, attempts=1)
resp = await self._run_git_cmd(
cmd, attempts=1, corrupt_hdr="fatal:"
)
except Exception:
attempts -= 1
resp = None
Expand Down Expand Up @@ -645,7 +647,7 @@ async def is_ancestor(
async with self.git_operation_lock:
for _ in range(attempts):
try:
await self._run_git_cmd(cmd, attempts=1, corrupt_msg="error: ")
await self._run_git_cmd(cmd, attempts=1, corrupt_hdr="error: ")
except self.cmd_helper.get_shell_command().error as err:
if err.return_code == 1:
return False
Expand Down Expand Up @@ -809,8 +811,7 @@ async def check_commit_exists(self, commit: str) -> bool:
shell_cmd = self.cmd_helper.get_shell_command()
try:
await self._run_git_cmd(
f"cat-file -e {commit}^{{commit}}", attempts=1,
corrupt_msg=None
f"cat-file -e {commit}^{{commit}}", attempts=1
)
except shell_cmd.error:
return False
Expand Down Expand Up @@ -1230,7 +1231,7 @@ def _handle_process_output(self, output: bytes) -> None:
self.fetch_input_recd = True
out = output.decode().strip()
if out:
if out.startswith("fatal: "):
if out.startswith("fatal: ") and "corrupt" in out:
self.repo_corrupt = True
self.git_messages.append(out)
self.cmd_helper.notify_update_response(out)
Expand Down Expand Up @@ -1265,7 +1266,7 @@ async def _run_git_cmd(
timeout: float = 20.,
attempts: int = 5,
env: Optional[Dict[str, str]] = None,
corrupt_msg: Optional[str] = "fatal: ",
corrupt_hdr: Optional[str] = None,
log_complete: bool = True
) -> str:
shell_cmd = self.cmd_helper.get_shell_command()
Expand All @@ -1288,10 +1289,10 @@ async def _run_git_cmd(
if stderr:
msg_lines.extend(stdout.split("\n"))
self.git_messages.append(stderr)
if corrupt_msg is not None:
if corrupt_hdr is not None:
for line in msg_lines:
line = line.strip().lower()
if line.startswith(corrupt_msg):
if line.startswith(corrupt_hdr) and "corrupt" in line:
self.repo_corrupt = True
break
raise

0 comments on commit 7f89bd7

Please sign in to comment.