Skip to content
This repository
Newer
Older
100644 136 lines (108 sloc) 4.489 kb
fccc6851 » MLstate
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (** folder.mli *)
19 (**
20 Simple file access library which provides a minimal
21 set of file and directory access functions but
22 maintains a list of authorized directories. Only
23 directories which are prefixed by one of the authorized
24 dirs are valid.
25 @author Norman Scaife
26 *)
27
28 exception Folder_error of string
29
30 (** Type of the folders. *)
31 type folder
32
33 (** empty dir: Return a new folder with the current dir
34 set to dir. We also add the initial directory to
35 the list of valid directories.
36 *)
37 val empty : string -> folder
38
39 (** current_folder folder: Return the current folder *)
40 val current_folder : folder -> string
41
42 (** valid_folders: return the current list of valid folders. *)
43 val get_valid_folders : folder -> string list
44
45 (** add_valid_folder folder dirname:
46 Add dirname to the current list of valid folders.
47 If the folder does not exist then raise Folder "not_found".
48 *)
49 val add_valid_folder : folder -> string -> unit
50
51 (** remove_valid_folder folder:
52 Remove the given folder from the valid folder list.
53 The name of the folder must match exactly, ie. "tmp/"
54 will not match "tmp".
55 If the current directory is a subdir of the one being
56 removed then the current dir is set to the first folder
57 in the valid folder list.
58 Note that this might not result in removing access to
59 the given directory if one of its parents is still in
60 the list.
61 WARNING: If the last valid folder is removed then the
62 current dir is technically in an unsafe state since
63 there is currently no way of flagging the non-existence
64 of the current dir.
65 *)
66 val remove_valid_folder : folder -> string -> unit
67
68 (** valid_folder folder filename
69 Test whether filename is accessible under folder.
70 *)
71 val valid_folder : folder -> string -> bool
72
73 (** writable_folder folder filename
74 Test if file is writable.
75 *)
76 val writable_folder : folder -> string -> bool
77
78 (** chfolder folder dirname:
79 Change current directory to dirname.
80 The dirname must be a subdirectory of one of the valid_folders.
81 *)
82 val chfolder : folder -> string -> unit
83
84 (** chfolderup folder:
85 Move up one folder checking that the parent folder is still valid.
86 *)
87 val chfolderup : folder -> unit
88
89 (** rename_folder:
90 We just do the rename under folder conventions, assume already valid
91 *)
92 val rename_folder : folder -> string -> string -> bool
93
94 (** delete_folder: Again, assume already valid *)
95 val delete_folder : folder -> string -> bool
96
97 (** create_directory: Again, assume already valid *)
98 val create_directory : folder -> string -> bool
99
100 (** delete_directory: Again, assume already valid *)
101 val delete_directory : folder -> string -> bool
102
103 (** list folder filename:
104 Return a directory listing of filename relative to folder
105 as an array of strings.
106 The . and .. directories are included.
107 The list is unsorted, it's in OS order.
108 We return None if the requested directory is inaccessible.
109 *)
110 val list : folder -> string -> string array option
111
112 (** ls_files folder filenames
113 Return a formatted list of "ls"-style file listings for a list of filenames.
114 *)
115 val ls_files : folder -> string array -> string array
116
117 (** openfileread/write/append folder filename:
118 Open a file for reading/writing/appending checking for validity, return file descriptor.
119 *)
120 val openfileread : folder -> string -> Unix.file_descr option
121 val openfilewrite : folder -> string -> Unix.file_descr
122 val openfileappend : folder -> string -> Unix.file_descr
123
124 (** lseek fd pos: seek to position pos from start of file *)
125 val lseek : Unix.file_descr -> int -> int
126
127 (** read fd amnt: read [amnt] bytes into a string *)
128 val read : Unix.file_descr -> int -> string
129
130 val write : Unix.file_descr -> string -> int -> int
131
132 (** closefile fd: close a file *)
133 val closefile : Unix.file_descr -> unit
134
135
136 (* End of file: folder.mli *)
Something went wrong with that request. Please try again.