+%
+<%args>
+ $path
+</%args>
+</%def>
+%
+%###-------------------------------------------------------------------------
+<%def .zip>\
+<%perl>
+ my $st = stat "$IMGROOT/$path";
+ if (!$st) { $m->comp(".not-found", path => $path); return; }
+ my $zip = "$TMP/t$$-download.zip";
+ my $err = "$TMP/t$$-download.stderr";
+ my $kid = fork;
+ if (!$kid) {
+ untie *STDIN; open STDIN, "</dev/null";
+ untie *STDOUT; open STDOUT, ">/dev/null";
+ untie *STDERR; open STDERR, ">", $err;
+ chdir "$IMGROOT/$path";
+ exec "zip", "-qr", $zip, ".";
+ exit 127;
+ }
+ waitpid $kid, 0;
+</%perl>
+%
+% if ($?) {
+<&| .html, title => "Zip failed (rc = $?)" &>
+<pre>
+<%perl>
+ open my $f, "<", $err;
+ my $buf;
+ while (read $f, $buf, 16384) { $m->print($buf); }
+</%perl>
+</pre>
+</&>
+% } else {
+<%perl>
+ $r->content_type("application/zip");
+ open my $f, "<", $zip; binmode $f;
+ my $buf;
+ while (read $f, $buf, 16384) { $m->print($buf); }
+</%perl>
+% }
+%
+<%perl>
+ eval { unlink $zip; };
+ eval { unlink $err; };
+</%perl>
+