From 25fdd2417360e16079c90d2f2160d6b6cd57c594 Mon Sep 17 00:00:00 2001 From: "J. Patrick Avery, Jr" Date: Sat, 6 Jun 2015 22:17:55 -0500 Subject: [PATCH] bin/once: fix points problem TODO: neale says points should be written to state/points.tmp then be moved into state/points.new to avoid race condition (multiple processes touching the file causing the file to change risking bad data in state/points.log). It might be wise to do some validation in bin/points that tosses bad data. --- bin/once | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/once b/bin/once index a5e9332..1f40248 100755 --- a/bin/once +++ b/bin/once @@ -16,11 +16,17 @@ fi # Collect new points find state/points.new -type f | while read fn; do - # Skip partially-written files - [ $(wc -l < $fn) -eq 1 ] || continue + # Skip files opened by another process + lsof $fn | grep -q $fn && continue + + # Skip partially written files + [ $(wc -l < $fn) -gt 0 ] || continue - cat $fn >> state/points.log - rm $fn + # filter the file for unique awards + sort -k 4 $fn | uniq -f 1 | sort -n >> state/points.log + + # Now kill the file + rm -f $fn done # Generate new puzzles.html