commit 033d2c2dd9c4697da07fc274e99164d52ecd7272 Author: Peter Tillemans Date: Wed Jan 29 09:06:47 2025 +0100 initial commit diff --git a/inotify-test.scm b/inotify-test.scm new file mode 100644 index 0000000..1a0db0a --- /dev/null +++ b/inotify-test.scm @@ -0,0 +1,26 @@ +(use-modules (rnrs io ports)) +(use-modules (ice-9 threads)) + + +(define (on-file-change fname thunk) + (let* ((input+output (pipe)) + (pid (spawn "inotifywait" `("inotifywait" "-m" ,fname) + #:output (cdr input+output)))) + (close-port (cdr input+output)) + (let loop ((line "dummy CLOSE_WRITE")) + (unless (eof-object? line) + (format #t "read ~s~%" line) + (if (string-contains line "CLOSE_WRITE") + (thunk)) + (loop (get-line (car input+output))))) + (close-port (car input+output)) + (waitpid pid))) + +(call-with-new-thread (lambda () (on-file-change "inotify-test.scm" (lambda () (format #t "file changed~%"))))) + +(format #t "waiting 30s for file change~%") +(do ((i 0 (+ i 1))) ((> i 30) (format #t "done loop~%")) + (sleep 1) + (format #t "tick~%")) +(format #t "done waiting~%") +