X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=blobdiff_plain;f=sa-learn-cache;fp=sa-learn-cache;h=b51c4e7490005c365447786c175e05dc06375359;hb=671daef7e5083b48b55fa799c40b9e6332693494;hp=0000000000000000000000000000000000000000;hpb=9b7b22d2e16376edc6049a81cd8ad00243f1dbd9;p=bin.git diff --git a/sa-learn-cache b/sa-learn-cache new file mode 100755 index 0000000..b51c4e7 --- /dev/null +++ b/sa-learn-cache @@ -0,0 +1,40 @@ +#! /bin/sh +# Depends: chiark-utils-bin +set -e + +DIR="$HOME/tmp/sa-learn-cache" + +LOCKED=false +if [ "$1" = --locked ]; then + LOCKED=: + shift +fi + +if [ "$1" = --spam ]; then + CACHE="$DIR/spam" +elif [ "$1" = --ham ]; then + CACHE="$DIR/ham" +else + echo "don't know how to handle anything other than --spam or --ham" >&2 + exit 1 +fi +LOCK="$CACHE.lock" + +mkdir -p "$DIR" + +if ! $LOCKED; then + exec with-lock-ex -w "$LOCK" "$0" --locked "$@" +else + if [ -e "$CACHE" ]; then + SIZE="$(stat -c %s "$CACHE")" + else + SIZE=0 + fi + cat >> "$CACHE" + if [ "$SIZE" -gt 4194304 ]; then + sa-learn --mbox --no-sync "$@" < "$CACHE" + rm -f "$CACHE" + fi +fi + +exit 0