1 (** Watches directories for events. Agnostic to vsys semantics of backends and
8 (* I don't know if a wd corresponding to a deleted directory is evicted or just
9 * leaks - fix implementation of rmdir accordingly
11 let wdmap = Hashtbl.create 1024
13 let fd = Inotify.init ()
15 let rec list_check lst elt =
18 | car::cdr -> if (car==elt) then true else list_check cdr elt
23 logprint "Event: %s\n" (string_of_event e))
26 let handle_dir_event dirname evlist str =
27 let fname = String.concat "/" [dirname;str] in
28 logprint "File: %s. " fname;
31 let add_watch dir events handler =
32 let wd = Inotify.add_watch fd dir events in
33 Hashtbl.add wdmap wd (dir,Some(handler))
34 (* Ignore the possibility that the whole directory can disappear and come
35 * back while it is masked *)
38 let rec findfirstnul str idx len =
40 (str.[idx]==(char_of_int 0))) then idx
42 findfirstnul str (idx+1) len
44 let nulterm = findfirstnul s 0 (String.length s) in
45 String.sub s 0 nulterm
47 let receive_event (eventdescriptor:fname_and_fd) (bla:fname_and_fd) =
48 let (_,fd) = eventdescriptor in
49 let evs = Inotify.read fd in
52 | (wd,evlist,_,Some(str)) ->
54 let purestr = asciiz(str) in
55 let (dirname,handler) =
56 try Hashtbl.find wdmap wd with Not_found->("",None)
60 logprint "Unhandled watch descriptor\n"
62 let fqp = String.concat "/" [dirname;purestr] in
64 handler wd dirname evlist
72 Fdwatcher.add_fd (None,fd) (None,fd) receive_event