From 91c607a7071ce02f2c35836ec6cbc62d9754cb81 Mon Sep 17 00:00:00 2001 From: sudolulo Date: Mon, 15 Jun 2026 03:43:03 +0000 Subject: [PATCH] Improve log rotation, early-exit find_bundle, fix uninstall orphaned backup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit apply.sh: preserve two log generations (.1 and .2) on rotation so the last two boots are always available for diagnosis. patch_ui.py: find_bundle returns on the first matching JS file instead of collecting all matches. The multi-match warning was dead weight — the Angular Ivy compiler produces exactly one bundle and the WARNING path was unreachable in practice. uninstall.sh: restore an orphaned sitecustomize.py.pre-truecloud-patch when sitecustomize.py itself has already been removed (e.g. manual deletion while the backup survived). Prevents leaving ghost vendor files in site-packages. --- patch/apply.sh | 2 ++ patch/patch_ui.py | 18 ++---------------- uninstall.sh | 9 +++++++++ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/patch/apply.sh b/patch/apply.sh index b39f590..23b9e36 100755 --- a/patch/apply.sh +++ b/patch/apply.sh @@ -22,7 +22,9 @@ PATCH_DIR="/data/truecloud-patch" LOG="$PATCH_DIR/apply.log" # Rotate log at 512 KB to avoid unbounded growth on a system volume. +# Keep one prior generation (.1) so the last two boots are always available. if [ -f "$LOG" ] && [ "$(wc -c < "$LOG")" -gt 524288 ]; then + [ -f "${LOG}.1" ] && mv "${LOG}.1" "${LOG}.2" mv "$LOG" "${LOG}.1" fi diff --git a/patch/patch_ui.py b/patch/patch_ui.py index 964a36d..1245c8b 100644 --- a/patch/patch_ui.py +++ b/patch/patch_ui.py @@ -50,7 +50,6 @@ def find_bundle(): if webui is None: return None, None, None - matches = [] for root, _dirs, names in os.walk(webui): for name in sorted(names): # deterministic order if not name.endswith(".js"): @@ -60,24 +59,11 @@ def find_bundle(): with open(path, encoding="utf-8", errors="replace") as fh: content = fh.read() if FIND.search(content): - matches.append((path, content)) + return webui, path, content except OSError: continue - if not matches: - return webui, None, None - - if len(matches) > 1: - # Unexpected — log all matches so the operator can investigate. - print( - f"[truecloud-patch] WARNING: filterByProviders pattern found in " - f"{len(matches)} files; patching only the first." - ) - for p, _ in matches: - print(f"[truecloud-patch] {p}") - - path, content = matches[0] - return webui, path, content + return webui, None, None def main(): diff --git a/uninstall.sh b/uninstall.sh index 9f8cb2e..358c99a 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -76,6 +76,15 @@ if [ -n "$SITE_PKG" ] && [ -f "$SITE_PKG/sitecustomize.py" ]; then else echo " Not found (already removed or install didn't place it here)." fi + +# Handle orphaned backup when sitecustomize.py was removed (e.g. by a TrueNAS +# update) but the .pre-truecloud-patch file survived in the same directory. +if [ -n "$SITE_PKG" ] && [ ! -f "$SITE_PKG/sitecustomize.py" ] && \ + [ -f "$SITE_PKG/sitecustomize.py.pre-truecloud-patch" ]; then + mv "$SITE_PKG/sitecustomize.py.pre-truecloud-patch" \ + "$SITE_PKG/sitecustomize.py" + echo " Restored orphaned sitecustomize.py backup" +fi echo "" # ── Restore UI bundle ─────────────────────────────────────────────────────────