*** empty log message ***
[vsys.git] / frontend.ml
1 open Printf
2 open Unix
3 open Globals
4 open Fifowatcher
5
6 class frontendHandler (root_dir,slice_name) = 
7 object(this)
8   method get_slice_name () = slice_name
9   method mkentry (rp:relpath) abspath perm = 
10             let realperm = perm land (lnot 0o111) in
11     match rp with Relpath(rel) ->
12       let fqp = String.concat "/" [root_dir;rel] in
13          Fifowatcher.mkentry fqp abspath realperm;
14          Fifowatcher.openentry fqp (abspath,slice_name) realperm
15
16   method mkdir rp perm =
17     match rp with Relpath(rel) ->
18     let fqp = String.concat "/" [root_dir;rel] in
19       try 
20             let s = Unix.stat fqp in
21               if (s.st_kind<>S_DIR) then
22                 begin
23                         Unix.unlink fqp;
24                         Unix.mkdir fqp perm
25                 end
26               else if (s.st_perm <> perm) then
27                 begin
28                         printf "Removing directory %s\n" fqp;
29                         flush Pervasives.stdout;
30                         Unix.rmdir fqp;
31                         Unix.mkdir fqp perm
32                 end
33       with Unix.Unix_error(_,_,_) ->
34         Unix.mkdir fqp perm
35
36   method unlink rp =
37     match rp with Relpath(rel) ->
38     let fqp1 = String.concat "/" [root_dir;rel;".in"] in
39     let fqp2 = String.concat "/" [root_dir;rel;".out"] in
40       try 
41       Unix.unlink fqp1;
42       Unix.unlink fqp2
43       with _ ->
44         printf "Hm. %s disappeared. Never mind\n" fqp1;flush Pervasives.stdout
45
46   method rmdir rp =
47     match rp with Relpath(rel) ->
48     let fqp = String.concat "/" [root_dir;rel] in
49       try
50       Unix.rmdir fqp
51       with _ ->
52         printf "Hm. %s disappeared. Never mind\n" fqp;flush Pervasives.stdout
53 end