(process-fork
 (lambda ()
   (init!)
   (on-exit clean-up!)
   (add-watch! (make-pathname (root-path) "paste/raw") '(move create delete))
   (define (watch-paste)
     (next-events!)
     (call-with-output-file (make-pathname (root-path) "paste/pastes" "html")
       (lambda (p)
           (for-each
            (lambda (f)
              (let ((f (pathname-file f)))
                (format p "<h2><a href=\"~a\">~a</a></h2>~n" f f)))
            (sort (directory (make-pathname (root-path) "paste/raw")) string>?))))
     (watch-paste))
   (watch-paste)))

plain