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;
+ List.iter
+ (fun e ->
+ logprint "Event: %s\n" (string_of_event e))
+ evlist
let add_watch dir events handler =
- let evcheck = list_check events in
- let oneshot = if (evcheck S_Oneshot) then true else false
- in
let wd = Inotify.add_watch fd dir events in
- Hashtbl.add masks dir (wd,handler);
- Hashtbl.add wdmap wd (dir,Some(handler),oneshot)
+ 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 =
+let mask_watch fqp =
try
- let wd,_ = Hashtbl.find masks dir in
- Inotify.rm_watch fd wd;
- Hashtbl.remove wdmap wd
+ print "Masking %s %d\n" fqp (String.length fqp);
+ Hashtbl.replace masks fqp true
with _ ->
()
-let unmask_watch dir events =
- let _,handler = Hashtbl.find masks dir in
- try
- Hashtbl.remove masks dir;
- add_watch dir events handler
- with Not_found -> ()
-
+let unmask_watch fqp =
+ if (Hashtbl.mem masks fqp) then
+ begin
+ Hashtbl.remove masks fqp
+ end
+ else
+ logprint "WARNING: %s -- Unpaired unmask\n" fqp
+
let asciiz s =
let rec findfirstnul str idx len =
if ((idx==len) ||
List.iter (fun x->
match x with
| (wd,evlist,_,Some(str)) ->
- let purestr = asciiz(str) in
- let (dirname,handler,oneshot) =
- try Hashtbl.find wdmap wd with Not_found->("",None,false)
- in
- if (oneshot) then Hashtbl.remove wdmap wd;
- (
- match handler with
- | None->fprintf logfd "Unhandled watch descriptor\n";flush logfd
- | Some(handler)->handler wd dirname evlist purestr
- )
+ begin
+ let purestr = asciiz(str) in
+ let (dirname,handler) =
+ try Hashtbl.find wdmap wd with Not_found->("",None)
+ in
+ match handler with
+ | None->logprint "Unhandled watch descriptor\n"
+ | Some(handler)->
+ let fqp = String.concat "/" [dirname;purestr] in
+ let mask_filter = Hashtbl.mem masks fqp in
+ begin
+ (*print "Received event for - %s\n"
+ * fqp;*)
+ if ((not mask_filter) && false) then
+ handler wd dirname evlist purestr
+ else
+ print "%s is masked\n" fqp
+ end
+ end
| _ -> ())
evs