From 033d2c2dd9c4697da07fc274e99164d52ecd7272 Mon Sep 17 00:00:00 2001 From: Peter Tillemans Date: Wed, 29 Jan 2025 09:06:47 +0100 Subject: [PATCH] initial commit --- inotify-test.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 inotify-test.scm 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~%") +