rm is reflected from the backend to the frontend again.
[vsys.git] / frontend.ml
1 (* frontend.ml: Routines that implement frontend actions, such as creating directories in a slice, creating pipes etc. *)
2
3 open Printf
4 open Unix
5 open Globals
6 open Fifowatcher
7
8 (** frontendhandler class: Methods to create and unlink pipes and directories 
9   @param root_dir vsys directory inside a slice
10   @param slice_name actual slice name - set with care, since the acl functionality refers to these names *)
11 class frontendHandler (root_dir,slice_name) = 
12 object(this)
13   method get_slice_name () = slice_name
14
15   (** A new script was copied into the backend, make a corresponding entry in
16     the frontend.
17     @param rp Relative path of the entry in the backend
18     @param abspath Absolute path of the entry
19     @param perm Permissions of the entry at the frontend *)
20   method mkentry (rp:relpath) abspath perm = 
21             let realperm = perm land (lnot 0o111) in
22     match rp with Relpath(rel) ->
23       let fqp = String.concat "/" [root_dir;rel] in
24       let res = Fifowatcher.mkentry fqp abspath realperm slice_name in
25         match res with 
26           | Success ->
27               Fifowatcher.openentry fqp (abspath,slice_name) realperm
28           | _ -> ()
29
30   (** A new directory was created at the backend, make a corresponding directory
31     at the frontend. Refer to mkentry for parameters *)
32   method mkdir rp perm =
33     match rp with Relpath(rel) ->
34     let fqp = String.concat "/" [root_dir;rel] in
35       try 
36             let s = Unix.stat fqp in
37               if (s.st_kind<>S_DIR) then
38                 begin
39                         Unix.unlink fqp;
40                         Unix.mkdir fqp perm
41                 end
42               else if (s.st_perm <> perm) then
43                 begin
44                         fprintf logfd "Removing directory %s\n" fqp;
45                         flush logfd;
46                         Unix.rmdir fqp;
47                         Unix.mkdir fqp perm
48                 end
49       with Unix.Unix_error(_,_,_) ->
50         Unix.mkdir fqp perm
51
52   (** Functions corresponding to file deletion/directory removal *)
53
54   (** *)
55   method unlink rp =
56     match rp with Relpath(rel) ->
57     let fqp1 = String.concat "/" [root_dir;rel] in
58     let fqp_in = String.concat "." [fqp1;"in"] in
59     let fqp2 = String.concat "/" [root_dir;rel] in
60     let fqp_out = String.concat "." [fqp2;"out"] in
61       try 
62         Unix.unlink fqp_in;
63         Unix.unlink fqp_out
64       with _ ->
65         fprintf logfd "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp1 (this#get_slice_name ());flush logfd
66
67   method rmdir rp =
68     match rp with Relpath(rel) ->
69     let fqp = String.concat "/" [root_dir;rel] in
70       try
71       Unix.rmdir fqp
72       with _ ->
73         fprintf logfd "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ());flush logfd
74 end