Skip to content

Commit 09a4e60

Browse files
Fix log cleanup function to create directory and restore logs
Ensure log directory exists before cleanup and enhance log deletion with restoration attempt.
1 parent 4cd7327 commit 09a4e60

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎MerlinAU.sh‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,7 @@ readonly POST_UPDATE_EMAIL_SCRIPT_HOOK="[ -x $ScriptFilePath ] && $POST_UPDATE_E
22502250
##------------------------------------------##
22512251
_CleanUpOldLogFiles_()
22522252
{
2253-
[ ! -d "$FW_LOG_DIR" ] && return 1
2253+
[ ! -d "$FW_LOG_DIR" ] && mkdir -p -m 755 "$FW_LOG_DIR"
22542254
local numLogFiles topLogFile savedTopLogFile=""
22552255

22562256
numLogFiles="$(ls -1lt "$FW_LOG_DIR"/*.log 2>/dev/null | wc -l)"
@@ -2270,7 +2270,18 @@ _CleanUpOldLogFiles_()
22702270
fi
22712271

22722272
# Delete logs older than 30 days #
2273-
/usr/bin/find -L "$FW_LOG_DIR" -name '*.log' -mtime +30 -exec rm {} \;
2273+
if ! /usr/bin/find -L "$FW_LOG_DIR" \
2274+
-name '*.log' \
2275+
-mtime +30 \
2276+
-exec rm -f {} \;
2277+
then
2278+
# Attempt restoration before returning failure.
2279+
[ -n "$savedTopLogFile" ] &&
2280+
[ -e "$savedTopLogFile" ] &&
2281+
mv -f "$savedTopLogFile" "$topLogFile" 2>/dev/null
2282+
2283+
return 1
2284+
fi
22742285

22752286
# Restore the most recent log file #
22762287
if [ -n "$topLogFile" ] && \

0 commit comments

Comments
 (0)