vsys. first checkin
[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 fqp = String.concat "/" [root_dir;rel] in
38       Unix.unlink fqp
39
40   method rmdir rp =
41     match rp with Relpath(rel) ->
42     let fqp = String.concat "/" [root_dir;rel] in
43       Unix.rmdir fqp
44 end