*** empty log message ***
[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          Fifowatcher.mkentry fqp abspath realperm;
25          Fifowatcher.openentry fqp (abspath,slice_name) realperm
26
27   (** A new directory was created at the backend, make a corresponding directory
28     at the frontend. Refer to mkentry for parameters *)
29   method mkdir rp perm =
30     match rp with Relpath(rel) ->
31     let fqp = String.concat "/" [root_dir;rel] in
32       try 
33             let s = Unix.stat fqp in
34               if (s.st_kind<>S_DIR) then
35                 begin
36                         Unix.unlink fqp;
37                         Unix.mkdir fqp perm
38                 end
39               else if (s.st_perm <> perm) then
40                 begin
41                         printf "Removing directory %s\n" fqp;
42                         flush Pervasives.stdout;
43                         Unix.rmdir fqp;
44                         Unix.mkdir fqp perm
45                 end
46       with Unix.Unix_error(_,_,_) ->
47         Unix.mkdir fqp perm
48
49   (** Functions corresponding to file deletion/directory removal *)
50
51   (** *)
52   method unlink rp =
53     match rp with Relpath(rel) ->
54     let fqp1 = String.concat "/" [root_dir;rel;".in"] in
55     let fqp2 = String.concat "/" [root_dir;rel;".out"] in
56       try 
57         Unix.unlink fqp1;
58         Unix.unlink fqp2
59       with _ ->
60         printf "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp1 (this#get_slice_name ());flush Pervasives.stdout
61
62   method rmdir rp =
63     match rp with Relpath(rel) ->
64     let fqp = String.concat "/" [root_dir;rel] in
65       try
66       Unix.rmdir fqp
67       with _ ->
68         printf "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ());flush Pervasives.stdout
69 end