cl-fswatch
is CFFI wrap of fswatch, a cross-platform file change monitor.
Copyright (c) 2016 Muyinliu Xing Released under the ISC License.
All available vis Quicklisp:
- cffi
- bordeaux-threads
wget --no-check-certificate https://github.com/emcrisostomo/fswatch/releases/download/1.9.2/fswatch-1.9.2.tar.gz
tar xzf fswatch-1.9.2.tar.gz
cd fswatch-1.9.2
./configure
make && make install
Note: current stable release is fswatch v1.9.2
TODO Don't know how to build DLL for fswatch on Windows yet. Welcome to reply.
In shell:
git clone https://github.com/muyinliu/cl-fswatch.git
cp -r cl-taobao ~/quicklisp/local-projects/
In Common Lisp:
(ql:quickload 'cl-fswatch)
Note: package cl-fswatch
has nicknames: fswatch
fsw
(defvar *session* (fsw:init-session))
(fsw:add-path *session* "/dir/to/watch")
(fsw:add-path *session* "/file/to/watch")
(defun fsw-event-callback (event-list)
"flags: pointer, array of fsw-event-flag."
(dolist (event event-list)
(destructuring-bind (path time flag-list)
event
(format t "path: ~S, evt_time: ~S, flag-list: (~{~S~^, ~})~%"
path
(universal-time->iso-time-string time)
flag-list))))
(fsw:set-callback *session* #'fsw-event-callback)
(fsw:start-monitor *session*) ;; will create a thread here
(cffi:use-foreign-library %libfswatch)
=>
debugger invoked on a CFFI:LOAD-FOREIGN-LIBRARY-ERROR in thread
#<THREAD "main thread" RUNNING {1002A9C6E3}>:
Unable to load foreign library (%LIBFSWATCH).
Error opening shared object "libfswatch.so":
libfswatch.so: cannot open shared object file: No such file or directory.
- Make sure the DLL file(
libfswatch.so
on Linux,libfswatch.dylib
on Mac OS X,libfswatch.dll
on Windows) built success - Make sure CFFI can find the DLL file(copy/symlink DLL to
/usr/lib/
on Mac/Linux, copy DLL toC:/Windows/System32
on Windows)
Looks like C function fsw_destroy_session
from libfswatch didn't work...
C API | require |
---|---|
fsw_init_library | 1.4.4+ |
fsw_init_session | 1.4.4+ |
fsw_add_path | 1.4.4+ |
fsw_add_property | 1.6.0+ |
fsw_set_allow_overflow | 1.6.0+ |
fsw_set_callback | 1.4.4+ |
fsw_set_latency | 1.4.4+ |
fsw_set_recursive | 1.4.4+ |
fsw_set_directory_only | 1.7.0+ |
fsw_set_follow_symlinks | 1.4.4+ |
fsw_add_event_type_filter | 1.5.0+ |
fsw_add_filter | 1.4.4+ |
fsw_start_monitor | 1.4.4+ |
fsw_destroy_session | 1.4.4+ |
fsw_last_error | 1.4.4+ |
fsw_is_verbose | 1.4.4+ |
fsw_set_verbose | 1.6.0+ |
Note: minimal required fswatch v1.4.4
Note: fsw_add_property
requires fswatch v1.6.0+