mirror of https://github.com/dirtbags/moth.git
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.
This commit is contained in:
parent
091a4cd848
commit
8166469fee
14
bin/once
14
bin/once
|
@ -16,11 +16,17 @@ fi
|
||||||
|
|
||||||
# Collect new points
|
# Collect new points
|
||||||
find state/points.new -type f | while read fn; do
|
find state/points.new -type f | while read fn; do
|
||||||
# Skip partially-written files
|
# Skip files opened by another process
|
||||||
[ $(wc -l < $fn) -eq 1 ] || continue
|
lsof $fn | grep -q $fn && continue
|
||||||
|
|
||||||
cat $fn >> state/points.log
|
# Skip partially written files
|
||||||
rm $fn
|
[ $(wc -l < $fn) -gt 0 ] || continue
|
||||||
|
|
||||||
|
# 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
|
done
|
||||||
|
|
||||||
# Generate new puzzles.html
|
# Generate new puzzles.html
|
||||||
|
|
Loading…
Reference in New Issue