* leaks - fix implementation of rmdir accordingly
*)
let wdmap = Hashtbl.create 1024
-let masks = Hashtbl.create 1024
let fd = Inotify.init ()
| [] -> false
| car::cdr -> if (car==elt) then true else list_check cdr elt
+let pevlist evlist =
+ List.iter
+ (fun e ->
+ logprint "Event: %s\n" (string_of_event e))
+ evlist
+
let handle_dir_event dirname evlist str =
let fname = String.concat "/" [dirname;str] in
- fprintf logfd "File: %s. " fname;List.iter
- (fun e ->
- fprintf logfd "Event: %s\n" (string_of_event e))
- evlist;
- flush logfd
+ logprint "File: %s. " fname;
+ pevlist evlist
let add_watch dir events handler =
- let evcheck = list_check events in
let wd = Inotify.add_watch fd dir events in
- Hashtbl.add masks dir (wd,handler);
Hashtbl.add wdmap wd (dir,Some(handler))
-
(* Ignore the possibility that the whole directory can disappear and come
* back while it is masked *)
-let mask_watch dir =
- try
- let wd,_ = Hashtbl.find masks dir in
- Inotify.rm_watch fd wd;
- Hashtbl.remove wdmap wd
- with _ ->
- ()
-
-let unmask_watch dir events =
- let _,handler = try Hashtbl.find masks dir with Not_found->fprintf logfd "unmask called without mask: %s\n" dir;flush logfd;raise Not_found in
- try
- Hashtbl.remove masks dir;
- add_watch dir events handler
- with Not_found -> ()
-
let asciiz s =
let rec findfirstnul str idx len =
if ((idx==len) ||
let (dirname,handler) =
try Hashtbl.find wdmap wd with Not_found->("",None)
in
- match handler with
- | None->fprintf logfd "Unhandled watch descriptor\n";flush logfd
- | Some(handler)->handler wd dirname evlist purestr
+ match handler with
+ | None->
+ logprint "Unhandled watch descriptor\n"
+ | Some(handler)->
+ let fqp = String.concat "/" [dirname;purestr] in
+ begin
+ handler wd dirname evlist
+ purestr
+ end
end
| _ -> ())
evs