From: Mark Wooding Date: Wed, 14 Jan 2015 14:23:27 +0000 (+0000) Subject: hush.in: Fix ordering of log files so we don't delete the wrong ones. X-Git-Tag: 1.3.1~1 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/misc/commitdiff_plain/f4dc42b818a17d8fa824b0b6341368ec1a46adcd hush.in: Fix ordering of log files so we don't delete the wrong ones. The sequence numbers aren't lexicographically ordered, so call out to sort(1) to put them in the right order. --- diff --git a/hush.in b/hush.in index 2752cdf..f10f507 100755 --- a/hush.in +++ b/hush.in @@ -163,19 +163,20 @@ exec 3>&- ###-------------------------------------------------------------------------- ### Delete old log files if there are too many. -## Count up the logfiles. -nlog=0 +## Find out the tails of the logfile names. We assume that we're responsible +## for all of these, and therefore that they're nicely formed. +logs="" nlog=0 for i in "$logdir/$tag".*; do if [ ! -f "$i" ]; then continue; fi nlog=$(( $nlog + 1 )) + logs="$logs ${i#$logdir/$tag.}" done ## If there are too many, go through and delete some early ones. if [ $nlog -gt $maxlog ]; then n=$(( $nlog - $maxlog )) - for i in "$logdir/$tag".*; do - if [ ! -f "$i" ]; then continue; fi - rm -f "$i" + for i in $logs; do echo $i; done | sort -t# -k1,1 -k2n | while read i; do + rm -f "$logdir/$tag.$i" n=$(( $n - 1 )) if [ $n -eq 0 ]; then break; fi done