X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=backend.ml;h=6743f8c1b6c7bf964c7d2c5ee54705cbc6a13f2e;hb=d6806401d23028bfe5df6c7c5e35ecfe5fc828e7;hp=7d00cfd6428d1b372a37dcd02dce5e2cde9f70ed;hpb=a9f606051125de2acc9140074f91054755fa67b4;p=vsys.git diff --git a/backend.ml b/backend.ml index 7d00cfd..6743f8c 100644 --- a/backend.ml +++ b/backend.ml @@ -46,7 +46,7 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = (** Regular expression that defines a legal script name. Filter out * temporary files using this *) - val file_regexp = Str.regexp "[a-zA-Z][a-zA-Z0-9_\.]*" + val file_regexp = Str.regexp "^[a-zA-Z][a-zA-Z0-9_\.]*$" val acl_file_regexp = Str.regexp ".*acl$" val dir_regexp = Str.regexp "^dir_"; @@ -58,8 +58,13 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = let s = Unix.stat fqp in List.iter (fun frontend-> - frontend#mkdir (mk_rel_path fqp) (s.st_perm); - Dirwatcher.add_watch fqp [S_Create;S_Delete] (Some(func))) + try begin + frontend#mkdir (mk_rel_path fqp) (s.st_perm); + Dirwatcher.add_watch fqp [S_Create;S_Delete] func + end + with _ -> + fprintf logfd "Could not create %s. Looks like a slice shot itself in the foot\n" fqp;flush logfd; + ) slice_list (** Somebody copied in a new script *) @@ -79,7 +84,7 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = with _ -> None in match next_item with - | None -> cur_filter + | None -> close_in acl_file;cur_filter | Some(item) -> Hashtbl.add cur_filter item true; read_acl cur_filter @@ -88,12 +93,14 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = with _ -> None + method is_acl fname = Str.string_match acl_file_regexp fname 0 + (** Gets called every time there's an inotify event at the backend @param dirname Name of the backend directory @param evlist Description of what happened @param fname Name of the file that the event applies to *) - method handle_dir_event dirname evlist fname = + method handle_dir_event _ dirname evlist fname = let fqp = String.concat "/" [dirname;fname] in if ((Str.string_match file_regexp fname 0) && not (Str.string_match acl_file_regexp fname 0)) then begin @@ -102,7 +109,7 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = let acl_filter = this#make_filter acl_fqp in let slice_list = match acl_filter with - | None -> frontend_lst + | None -> [] (* No ACL *) | Some(filter) -> List.filter (fun fe->Hashtbl.mem filter (fe#get_slice_name ())) frontend_lst in let is_event = list_check evlist in @@ -147,16 +154,18 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = let cont = ref true in while (!cont) do try - let curfile = readdir dir_handle in + let curfile = readdir dir_handle in + if (not (this#is_acl curfile)) then + begin let fqp = String.concat "/" [dir;curfile] in let acl_fqp = String.concat "." [fqp;"acl"] in let acl_filter = this#make_filter acl_fqp in let slice_list = match acl_filter with - | None -> frontend_lst + | None -> [] (*frontend_lst -> No ACL => No Show *) | Some(filter) -> List.filter (fun fe->Hashtbl.mem filter (fe#get_slice_name ())) frontend_lst in - if (Str.string_match file_regexp curfile 0 && not (Str.string_match acl_file_regexp curfile 0)) then + if (Str.string_match file_regexp curfile 0) then let s = Unix.stat fqp in begin match s.st_kind with @@ -166,14 +175,15 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = | S_REG -> this#new_script slice_list fqp | _ -> - printf "Don't know what to do with %s\n" curfile;flush Pervasives.stdout + fprintf logfd "Don't know what to do with %s\n" curfile;flush logfd end - with - _->cont:=false;() + end + with _ + ->cont:=false;() done in begin build_initial_tree dir_root; - Dirwatcher.add_watch dir_root [S_Create;S_Delete] (Some(this#handle_dir_event)); + Dirwatcher.add_watch dir_root [S_Create;S_Delete] (this#handle_dir_event); end end