edge-host: fix settings-backup terminator check (trailing newline)

The zwave-js settings backup guard in #120 checked `tail -c1 == "}"`, but
settings.json ends with "}\n" — so the last byte is a newline and the guard
always skipped ("not }-terminated"), producing no backup. Strip trailing
whitespace before the check so a valid, newline-terminated file is backed up
while a genuinely truncated one is still rejected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-07 11:39:07 +02:00
co-authored by Claude Opus 4.8
parent c2f1aad8f7
commit f6f9d550bc
@@ -11,8 +11,9 @@ bak="$src.bak"
# Only back up a plausibly-intact file: non-empty and JSON-object-terminated.
# This avoids overwriting a good backup with a truncated (mid-write) file.
# Ignore trailing whitespace — settings.json ends with "}\n".
[ -s "$src" ] || { echo "settings.json missing/empty — skip"; exit 0; }
[ "$(tail -c1 "$src")" = "}" ] || { echo "settings.json not }-terminated (mid-write?) — skip"; exit 0; }
[ "$(tail -c 64 "$src" | tr -d '[:space:]' | tail -c1)" = "}" ] || { echo "settings.json not }-terminated (mid-write?) — skip"; exit 0; }
# Skip if unchanged since the last backup.
if [ -f "$bak" ] && cmp -s "$src" "$bak"; then