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
259339736c
commit
257933365e
14
bin/once
14
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
|
||||
|
||||
cat $fn >> state/points.log
|
||||
rm $fn
|
||||
# Skip partially written files
|
||||
[ $(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
|
||||
|
||||
# Generate new puzzles.html
|
||||
|
|
Loading…
Reference in New Issue