shithub: werc

ref: b862d00443c95bf5ab8bc8dc396f42a4b4e5a46f
dir: /bin/fproc_cache.rc/

View raw version
#!/usr/bin/env rc
#. 9.rc # Not really needed when calling from werc, only would be needed if you use fproc_cache.rc standalone

proc=$1

tmpfile=/tmp/fmttmp.$pid
score=`{{tee $tmpfile || exit 1} | sha1sum}

cachedir=/tmp/fproc_cache/$score
mkdir -p $cachedir >[2]/dev/null

if(test -s $cachedir/$proc)
    cat $cachedir/$proc
if not {
    # XXX For reliability mv should not be called unless both $proc and tee suceed
    $proc < $tmpfile | tee $cachedir/$pid
    mv $cachedir/$pid $cachedir/$proc
}
rm $tmpfile >[2]/dev/null