Merge pull request #216 from george231224/fix/check-perms-stat-linux

fix: use GNU stat first in check_perms (Linux false-warn)
This commit is contained in:
Matt Van Horn
2026-04-13 17:55:21 -04:00
committed by GitHub
+5 -1
View File
@@ -12,7 +12,11 @@ check_perms() {
local file="$1" local file="$1"
if [[ ! -f "$file" ]]; then return; fi if [[ ! -f "$file" ]]; then return; fi
local perms 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 if [[ -n "$perms" && "$perms" != "600" && "$perms" != "400" ]]; then
echo "/last30days: WARNING — $file has permissions $perms (should be 600)." echo "/last30days: WARNING — $file has permissions $perms (should be 600)."
echo " Fix: chmod 600 $file" echo " Fix: chmod 600 $file"