Minor optimizations and reliability improvments to fproc_cache.

This commit is contained in:
Uriel 2009-01-07 23:50:49 +01:00
parent 57865a60ec
commit 4eb8e0641e

View file

@ -1,8 +1,9 @@
#!/usr/bin/env rc #!/usr/bin/env rc
#. 9.rc # Not really needed when calling from werc, only would be needed if you use fproc_cache.rc standalone #. 9.rc # Not really needed when calling from werc, only would be needed if you use fproc_cache.rc standalone
# TODO: Allow to provide two arguments, second arg is a file name, use filename+size+mtime for hashing.
# Useful when dealing with many big files (eg., thumb gallery generation).
proc=$1 proc=$1
tmpfile=/tmp/fmttmp.$pid tmpfile=/tmp/fmttmp.$pid
score=`{{tee $tmpfile || exit 1} | sha1sum} score=`{{tee $tmpfile || exit 1} | sha1sum}
@ -11,9 +12,8 @@ mkdir -p $cachedir >[2]/dev/null
if(test -s $cachedir/$proc) if(test -s $cachedir/$proc)
cat $cachedir/$proc cat $cachedir/$proc
if not { if not
# XXX For reliability mv should not be called unless both $proc and tee suceed if($proc < $tmpfile | tee $cachedir/$pid)
$proc < $tmpfile | tee $cachedir/$pid mv $cachedir/$pid $cachedir/$proc
mv $cachedir/$pid $cachedir/$proc
} rm $tmpfile $cachedir/$pid >[2]/dev/null &
rm $tmpfile >[2]/dev/null