From 3d57db9644ab5c17f35a946bd67200946c50a854 Mon Sep 17 00:00:00 2001 From: george231224 Date: Sat, 11 Apr 2026 18:41:08 +0800 Subject: [PATCH] fix: use GNU stat first in check_perms so Linux doesn't false-warn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `stat -f '%Lp'` is BSD/macOS syntax. On Linux, `stat -f` prints filesystem info (Block size / Inodes / ...) and still exits 0, so the `||` fallback to `stat -c '%a'` never fires. That left `$perms` as multi-line garbage, the `!= "600"` check was always true, and every Linux SessionStart hook invocation printed a bogus warning plus the whole `stat -f` filesystem dump. Reorder to try GNU stat first, fall back to BSD for macOS. Verified on Linux (cpython-3.12 / bash 5.x) — hook now emits the expected compact Ready banner with no false warning. Co-Authored-By: Claude Opus 4.6 (1M context) --- hooks/scripts/check-config.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hooks/scripts/check-config.sh b/hooks/scripts/check-config.sh index 3fba6e0..39b4bbd 100755 --- a/hooks/scripts/check-config.sh +++ b/hooks/scripts/check-config.sh @@ -12,7 +12,11 @@ check_perms() { local file="$1" if [[ ! -f "$file" ]]; then return; fi local perms - perms=$(stat -f '%Lp' "$file" 2>/dev/null || stat -c '%a' "$file" 2>/dev/null || echo "") + # Try GNU stat first (Linux), fall back to BSD stat (macOS). + # On Linux, `stat -f` prints filesystem info (not permissions) and exits 0, + # so the previous BSD-first ordering left $perms as multi-line garbage on + # every Linux session start and printed a false WARNING. + perms=$(stat -c '%a' "$file" 2>/dev/null || stat -f '%Lp' "$file" 2>/dev/null || echo "") if [[ -n "$perms" && "$perms" != "600" && "$perms" != "400" ]]; then echo "/last30days: WARNING — $file has permissions $perms (should be 600)." echo " Fix: chmod 600 $file"