From 7e9f87d2279cb18ac1807bbd1d97c180cadce6e4 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 27 Apr 2026 09:16:18 -0500 Subject: fix(log-cleanup): handle filenames without YYYY-MM-DD via epoch fallback If no YYYY-MM-DD matches, the script now looks for a 10-digit epoch between underscores in the filename and converts it via date -d. The existing 24-hour mtime guard still protects the active session log from being deleted while it's still being written to. --- dotfiles/common/.local/bin/cron/log-cleanup | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dotfiles/common/.local/bin/cron/log-cleanup b/dotfiles/common/.local/bin/cron/log-cleanup index e8d6ac4..b2d1fbb 100755 --- a/dotfiles/common/.local/bin/cron/log-cleanup +++ b/dotfiles/common/.local/bin/cron/log-cleanup @@ -19,8 +19,15 @@ cutoff=$(date -d "$DAYS days ago" +%Y%m%d) for f in "$LOG_DIR"/*.log; do [ -f "$f" ] || continue - # Extract YYYY-MM-DD from filename; skip files without a date - filedate=$(basename "$f" | grep -oP '\d{4}-\d{2}-\d{2}' | head -1) + # Extract YYYY-MM-DD from filename, or fall back to an embedded + # _<10-digit-epoch>_ (used by hyprland-runtime logs which lack a + # human-readable date in the filename). Skip files with neither. + name=$(basename "$f") + filedate=$(echo "$name" | grep -oP '\d{4}-\d{2}-\d{2}' | head -1) + if [ -z "$filedate" ]; then + epoch=$(echo "$name" | grep -oP '_\K[0-9]{10}(?=_)' | head -1) + [ -n "$epoch" ] && filedate=$(date -d "@$epoch" +%Y-%m-%d 2>/dev/null) + fi [ -n "$filedate" ] || continue # Skip files still being written to (modified in the last 24h). # This prevents deleting active logs from long-running sessions. -- cgit v1.2.3