fixed build issue
[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 mkentry (rp:relpath) abspath perm = 
9             let realperm = perm land (lnot 0o111) in
10     match rp with Relpath(rel) ->
11       let fqp = String.concat "/" [root_dir;rel] in
12          Fifowatcher.mkentry fqp abspath realperm;
13          Fifowatcher.openentry fqp (abspath,slice_name) realperm
14
15   method mkdir rp perm =
16     match rp with Relpath(rel) ->
17     let fqp = String.concat "/" [root_dir;rel] in
18       try 
19             let s = Unix.stat fqp in
20               if (s.st_kind<>S_DIR) then
21                 begin
22                         Unix.unlink fqp;
23                         Unix.mkdir fqp perm
24                 end
25               else if (s.st_perm <> perm) then
26                 begin
27                         printf "Removing directory %s\n" fqp;
28                         flush Pervasives.stdout;
29                         Unix.rmdir fqp;
30                         Unix.mkdir fqp perm
31                 end
32       with Unix.Unix_error(_,_,_) ->
33         Unix.mkdir fqp perm
34
35   method unlink rp =
36     match rp with Relpath(rel) ->
37     let fqp1 = String.concat "/" [root_dir;rel;".in"] in
38     let fqp2 = String.concat "/" [root_dir;rel;".out"] in
39       try 
40       Unix.unlink fqp1;
41       Unix.unlink fqp2
42       with _ ->
43         printf "Hm. %s disappeared. Never mind\n" fqp1;flush Pervasives.stdout
44
45   method rmdir rp =
46     match rp with Relpath(rel) ->
47     let fqp = String.concat "/" [root_dir;rel] in
48       try
49       Unix.rmdir fqp
50       with _ ->
51         printf "Hm. %s disappeared. Never mind\n" fqp;flush Pervasives.stdout
52 end