git_deploy: limit corruption detection

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-05-28 12:35:52 -04:00
parent 3b1c21a72d
commit 7f89bd7d62
1 changed files with 9 additions and 8 deletions

View File

@ -412,7 +412,9 @@ class GitRepo:
self.git_messages.clear() self.git_messages.clear()
try: try:
cmd = "status --porcelain -b" 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: except Exception:
attempts -= 1 attempts -= 1
resp = None resp = None
@ -645,7 +647,7 @@ class GitRepo:
async with self.git_operation_lock: async with self.git_operation_lock:
for _ in range(attempts): for _ in range(attempts):
try: 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: except self.cmd_helper.get_shell_command().error as err:
if err.return_code == 1: if err.return_code == 1:
return False return False
@ -809,8 +811,7 @@ class GitRepo:
shell_cmd = self.cmd_helper.get_shell_command() shell_cmd = self.cmd_helper.get_shell_command()
try: try:
await self._run_git_cmd( await self._run_git_cmd(
f"cat-file -e {commit}^{{commit}}", attempts=1, f"cat-file -e {commit}^{{commit}}", attempts=1
corrupt_msg=None
) )
except shell_cmd.error: except shell_cmd.error:
return False return False
@ -1230,7 +1231,7 @@ class GitRepo:
self.fetch_input_recd = True self.fetch_input_recd = True
out = output.decode().strip() out = output.decode().strip()
if out: if out:
if out.startswith("fatal: "): if out.startswith("fatal: ") and "corrupt" in out:
self.repo_corrupt = True self.repo_corrupt = True
self.git_messages.append(out) self.git_messages.append(out)
self.cmd_helper.notify_update_response(out) self.cmd_helper.notify_update_response(out)
@ -1265,7 +1266,7 @@ class GitRepo:
timeout: float = 20., timeout: float = 20.,
attempts: int = 5, attempts: int = 5,
env: Optional[Dict[str, str]] = None, env: Optional[Dict[str, str]] = None,
corrupt_msg: Optional[str] = "fatal: ", corrupt_hdr: Optional[str] = None,
log_complete: bool = True log_complete: bool = True
) -> str: ) -> str:
shell_cmd = self.cmd_helper.get_shell_command() shell_cmd = self.cmd_helper.get_shell_command()
@ -1288,10 +1289,10 @@ class GitRepo:
if stderr: if stderr:
msg_lines.extend(stdout.split("\n")) msg_lines.extend(stdout.split("\n"))
self.git_messages.append(stderr) self.git_messages.append(stderr)
if corrupt_msg is not None: if corrupt_hdr is not None:
for line in msg_lines: for line in msg_lines:
line = line.strip().lower() line = line.strip().lower()
if line.startswith(corrupt_msg): if line.startswith(corrupt_hdr) and "corrupt" in line:
self.repo_corrupt = True self.repo_corrupt = True
break break
raise raise