shithub: werc

Download patch

ref: fa6225633570415388944b69f576dc6f6fa3c214
parent: ee748abf0f4f4845eda50886d6164e14a3c1fef1
author: uriel <uriel@engel.se.cat-v.org>
date: Fri Feb 6 15:42:15 EST 2009

Make fproc_cache take an optional second arg that can be a file or dir name, if provided that file/path will be used as input for the first argument removing the need for a temporary file.

--- a/bin/fproc_cache.rc
+++ b/bin/fproc_cache.rc
@@ -1,12 +1,27 @@
 #!/usr/bin/env rc
 #. 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).
 
+a=()
+tmpf=()
+
 proc=$1
-tmpfile=/tmp/fmttmp.$pid
-score=`{{tee $tmpfile || exit 1} | sha1sum}
+shift
 
+if(~ $#* 0) {
+    tmpf=/tmp/fmttmp.$pid
+    f=$tmpf
+    score=`{{tee $tmpf || exit 1} | sha1sum}
+}
+if not {
+    f=$1
+    if(~ $f */) {
+        score=`{du -an $f | sha1sum || exit 1} # XXX using -n(bytes) instead of -t(lastmod) because sitemap proc touches files in tree.
+        a=$f
+        f=/dev/null
+    }
+    if not
+        score=`{sha1sum $f || exit 1}
+}
 cachedir=/tmp/fproc_cache/$score
 mkdir -p $cachedir >[2]/dev/null
 
@@ -13,7 +28,7 @@
 if(test -s $cachedir/$proc)
     cat $cachedir/$proc
 if not
-    if($proc < $tmpfile | tee $cachedir/$pid)
+    if($proc $a < $f | tee $cachedir/$pid)
         mv $cachedir/$pid $cachedir/$proc
 
-rm $tmpfile $cachedir/$pid >[2]/dev/null &
+rm $tmpf $cachedir/$pid >[2]/dev/null &