From 481b570dae495807ba8a8f0b4d3fa7cd1ab8cf24 Mon Sep 17 00:00:00 2001 From: codefiles <11915375+codefiles@users.noreply.github.com> Date: Mon, 4 Nov 2024 06:38:58 -0500 Subject: [PATCH] Move logging code outside of command execution try-except block (#2739) --- archinstall/lib/general.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 9ef6926c..6ec9b37e 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -302,28 +302,29 @@ class SysCommandWorker: # https://stackoverflow.com/questions/4022600/python-pty-fork-how-does-it-work if not self.pid: history_logfile = pathlib.Path(f"{storage['LOG_PATH']}/cmd_history.txt") + + change_perm = False + if history_logfile.exists() is False: + change_perm = True + try: - change_perm = False - if history_logfile.exists() is False: - change_perm = True + with history_logfile.open("a") as cmd_log: + cmd_log.write(f"{time.time()} {self.cmd}\n") - try: - with history_logfile.open("a") as cmd_log: - cmd_log.write(f"{time.time()} {self.cmd}\n") + if change_perm: + os.chmod(str(history_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) + except (PermissionError, FileNotFoundError): + # If history_logfile does not exist, ignore the error + pass + except Exception as e: + exception_type = type(e).__name__ + error(f"Unexpected {exception_type} occurred in {self.cmd}: {e}") + raise e - if change_perm: - os.chmod(str(history_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) - except (PermissionError, FileNotFoundError): - # If history_logfile does not exist, ignore the error - pass - except Exception as e: - exception_type = type(e).__name__ - error(f"Unexpected {exception_type} occurred in {self.cmd}: {e}") - raise e - - if storage.get('arguments', {}).get('debug'): - debug(f"Executing: {self.cmd}") + if storage.get('arguments', {}).get('debug'): + debug(f"Executing: {self.cmd}") + try: os.execve(self.cmd[0], list(self.cmd), {**os.environ, **self.environment_vars}) except FileNotFoundError: error(f"{self.cmd[0]} does not exist.")