6 (* I don't know if a wd corresponding to a deleted directory is evicted or just
7 * leaks - fix implementation of rmdir accordingly
10 let wdmap = Hashtbl.create 1024
12 let fd = Inotify.init ()
14 let handle_dir_event dirname evlist str =
15 let fname = String.concat "/" [dirname;str] in
16 printf "File: %s. " fname;List.iter
18 printf "Event: %s\n" (string_of_event e))
20 flush Pervasives.stdout
22 let add_watch dir events handler =
23 printf "Adding watch for %s\n" dir;
24 let wd = Inotify.add_watch fd dir events in
25 Hashtbl.add wdmap wd (dir,handler)
28 let rec findfirstnul str idx len =
30 (str.[idx]==(char_of_int 0))) then idx
32 findfirstnul str (idx+1) len
34 let nulterm = findfirstnul s 0 (String.length s) in
35 String.sub s 0 nulterm
37 let receive_event (eventdescriptor:fd_and_fname) (bla:fd_and_fname) =
38 let (_,fd) = eventdescriptor in
39 let evs = Inotify.read fd in
42 | (wd,evlist,_,Some(str)) ->
43 let purestr = asciiz(str) in
44 let (dirname,handler) =
45 try Hashtbl.find wdmap wd with Not_found->printf "Unknown watch descriptor\n";raise Not_found
49 | None->handle_dir_event dirname evlist purestr
50 | Some(handler)->handler dirname evlist purestr
56 Fdwatcher.add_fd (None,fd) (None,fd) receive_event