X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=dirwatcher.ml;h=53c4c1cddfac4b57d6e00801cf84221738c3cd25;hb=4eccf5deff6324957d0bf0799dee6decb8d5f05a;hp=31226427f80f94d43d4f89e7ec18a09155b934ca;hpb=acbdd1601fcfb161089d326e7e32b74b76f441e3;p=vsys.git diff --git a/dirwatcher.ml b/dirwatcher.ml index 3122642..53c4c1c 100644 --- a/dirwatcher.ml +++ b/dirwatcher.ml @@ -9,7 +9,6 @@ open Globals * leaks - fix implementation of rmdir accordingly *) let wdmap = Hashtbl.create 1024 -let masks = Hashtbl.create 1024 let fd = Inotify.init () @@ -18,35 +17,23 @@ let rec list_check lst elt = | [] -> 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 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 file = - try - Hashtbl.replace masks (dir,file) true - with _ -> - () - -let unmask_watch dir file = - if (Hashtbl.mem masks (dir,file)) then - begin - Hashtbl.remove masks (dir,file) - end - else - fprintf logfd "WARNING: %s,%s -- Unpaired unmask\n" dir file;flush logfd - let asciiz s = let rec findfirstnul str idx len = if ((idx==len) || @@ -68,12 +55,15 @@ let receive_event (eventdescriptor:fname_and_fd) (bla:fname_and_fd) = 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)-> - let mask_filter = Hashtbl.mem masks (dirname,purestr) in - if (not mask_filter) then - 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