diff --git a/tools/btoperator.py b/tools/btoperator.py index fa9a0e9..72ec3f2 100644 --- a/tools/btoperator.py +++ b/tools/btoperator.py @@ -36,6 +36,24 @@ from PySide6.QtWidgets import ( HERE = os.path.dirname(os.path.abspath(__file__)) REPO = os.path.abspath(os.path.join(HERE, "..")) CONTENT = os.path.join(REPO, "content") + +def rotate_log(path): + """Keep the PREVIOUS run's log as .1 instead of destroying it. + + 2026-07-26 games night: the crash self-report block and the whole 23:08 + session's relay log were both lost to truncation minutes after they were + written -- Start Session zeroed operator_relay.log and Launch-instances + os.remove()'d the pod log. One generation of history is cheap insurance. + """ + try: + if os.path.exists(path): + prev = path + ".1" + if os.path.exists(prev): + os.remove(prev) + os.replace(path, prev) + except OSError: + pass # a locked log must never block a session + DEFAULT_EXE = os.path.join(REPO, "build", "Release", "btl4.exe") DEFAULT_EGG = os.path.join(CONTENT, "OPERATOR.EGG") BTCONSOLE = os.path.join(HERE, "btconsole.py") @@ -879,10 +897,8 @@ class Operator(QMainWindow): for tag in tags: host, _, port = tag.rpartition(":") args.append("%s:%d" % (host, int(port) - 1)) - try: # fresh relay log per session - open(os.path.join(CONTENT, "operator_relay.log"), "w").close() - except OSError: - pass + # fresh relay log per session -- the OLD session survives as .1 + rotate_log(os.path.join(CONTENT, "operator_relay.log")) self.console_proc = QProcess(self) self.console_proc.setProcessChannelMode(QProcess.MergedChannels) self.console_proc.readyReadStandardOutput.connect(self._console_output) @@ -1284,10 +1300,7 @@ class Operator(QMainWindow): # chain (each generation used to TRUNCATE the log -- the night-2 # crash loop left a 2-line file). Fresh file per launch press. log_name = "operator_%d.log" % (r + 1) - try: - os.remove(os.path.join(CONTENT, log_name)) - except OSError: - pass + rotate_log(os.path.join(CONTENT, log_name)) env.insert("BT_LOG", log_name) env.insert("BT_LOG_APPEND", "1") proc = QProcess(self)