Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 327 lines (275 sloc) 10.651 kb
fccc685 Initial open-source release
MLstate authored
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 (** Rights for files. *)
19 val default_rights : int
20
21 val path_sep : string
22 (**
23 The path separator, ["/"] on Unix, ["\\"] on Windows
24 *)
25
26 val exists : string -> bool
27 (**
28 Checks if the file exists
29 *)
30
31 val copy : ?force:bool -> string -> string -> int
32 (**
33 [copy ?force source target] copy the content of file named [source]
34 into the file [target]
35 It will create any directory that is needed
36 If [force] is set, then [copy] occurs when though [target] exists
37 @return The exit code of the underlying command
38 *)
39
40 val mv : ?force:bool -> string -> string -> int
41 (**
42 [mv ?force source target] mv the content of file named [source]
43 into the file [target]
44 It will create any directory that is needed
45 If [force] is set, then [mv] occurs when though [target] exists
46 @return The exit code of the underlying command
47 *)
48
49 val extension : string -> string
50 (**
51 [extension filename] computes the extension of the file, ie the substring of
52 [filename] between the last dot and the end of the file
53 Returns the empty string is [filename] contains no dot.
54 *)
55
56 val chop_extension : string -> string
57 (**
58 [chop_extension] removes the extension of the filename (as defined above)
59 or does nothing when there is no extension
60 *)
61
62 val module_name : string -> string
63 (**
64 [module_name filename] returns the name of the caml module that is defined by that name
65 ie ["Pervasives"] for ["pervasives.ml"]
66 *)
67
68 val is_relative_include_path : string -> bool
69 (**
70 [is_relative_include_path filename] tells you if the filename (in a format accepted by
71 the -I option of ocamlc is relative to the current directory
72 ie: [is_relative_include_path "dir"] is [true]
73 [is_relative_include_path "/path/to/dir"] is [false]
74 [is_relative_include_path "+dir"] is [false]
75 (it is relative to the stdlib, not to the current directory)
76 *)
77
78 val subst : (string * string) list -> string -> string
79 (**
80 [subst ext_assoc filename] replacing the extension of [filename]
81 with its image through [ext_assoc]
82 If the image doesn't exist, then the original string is returned
83 If the image is [""], then the extension is stripped off ([subst \[("ml","")\] "a.ml"] is ["a"], not ["a."])
84 *)
85
86 val from_pattern : string -> string -> string
87 (**
88 [from_pattern pattern path]
89 @return [pattern] where the following sequences are replaced:
90 - ["%b"] by the basename of [path]
91 - ["%_b"] by the basename of [path] where dots are replaced by underscores
92 - ["%d"] by the dirname of [path]
93 - ["%e"] by the extension of [path]
94 - ["%"] by [path] without its extension
95 - ["%_"] by [path] without its extension and where dots are replaced by underscores
96 Note that you cannot escape ['%'].
97 *)
98
99 val content : string -> string
100 (**
101 @param f the filename
102 @return The content of the file as one string
103 @raise Unix.Unix_error ? if the file doesn't exists
104 @raise Failure if the file is a directory
105 *)
106
107 val content_opt : string -> string option
108 (**
109 @param f the filename to read
978b7c4 @akoprow [fix] typo: occurence->occurrence, occured->occurred
akoprow authored
110 @return [None] if an error occurred, [Some] of the content instead
fccc685 Initial open-source release
MLstate authored
111 *)
112
53cc032 [fix] mime: update deprecated option
Raja authored
113 val mimetype : ?mime_db:string -> string -> string
fccc685 Initial open-source release
MLstate authored
114 (**
115 @return the mimetype of the given filename
53cc032 [fix] mime: update deprecated option
Raja authored
116 @param mime_db is a filename as accepted by the -m option of the command file
fccc685 Initial open-source release
MLstate authored
117 *)
118
119 val is_relative: string -> bool
120 (**
121 Determine if a path is relative
122 *)
123
124 val normalize_relative_path: string -> string option
125 (**
126 Normalize a relative path.
127
128 - "/foo" -> None
129 - "./foo" -> Some "foo"
130 - "foo" -> Some "foo"
131 - "a/b/c/../../d" -> Some "a/d"
132 *)
133
134 val explicit_path : string -> string option -> string
135 (**
136 According given path and prefix, clean and explicit it :
137 Exemple :
138 explicit_path "/profA/profB/profC/../profC1/../../profB1/.///./profC2/./profD/profE/.././" None;;
139 - string = "/profA/profB1/profC2/profD"
140 @param path : the path can be absolute or relative.
141 @param prefix : optionnal prefix
142
143 If the path is absolute, it is jsut cleaned
144 If it is relative, and there is no prefix given, current absolute path is retrieved [Sys.getcwd] and concatenated to path, and then produced path is cleaned
145 If it is relative, and a preifx is given, they are jsute concatenated and cleaned
146 if path and prefix are relatives, they are concatenated, then current absolute path is concateneted to produced path, and finaly, all is cleaned
147 *)
148
149 val clean_beginning_path : string -> string
150 (**
151 According given path, clean it's beginning and verify that rest of the path has not relatif parts
152 Exemple :
153 clean_beginning_path "../.././toto/titi";;
154 - : string = "/toto/titi"
155 clean_beginning_path "../.././toto/./titi";;
156 Exception: Failure "\"../.././toto/./titi\" : End of path is not clean".
157 *)
158
159 val last_modification : string -> Time.t
160 (**
161 [last_modification filename]
162 @return the time as described by [Unix.time]
163 @raise Unix_error _ if [filename] doesn't exists
164 *)
165
166 val virtual_content : int -> string -> string
167
168 val lines_fold : ('a -> string -> 'a) -> 'a -> string -> 'a
169 (**
170 [lines_fold f acc filename] opens the file [filename] and gives
171 every line to [f], along with [acc].
172 *)
173
174 val lines_foldi : ('a -> string -> int -> 'a) -> 'a -> string -> 'a
175 (**
176 same as [lines_fold], but [f] is also given the line number
177 (starting from 1)
178 *)
179
180 val lines_foldi_offset : ('a -> string -> int -> int -> 'a) -> 'a -> string -> 'a
181 (**
182 same as [lines_foldi], but [f] is also given the global offset
183 of the beginning of the line (starting from 0)
184 *)
185
186 val lines_mapi : (string -> int -> 'a) -> string -> 'a list
187 (**
188 [lines_mapi f filename]
189 maps through the lines of [filename]
190 *)
191
192 val lines_rev_mapi : (string -> int -> 'a) -> string -> 'a list
193 (**
194 [lines_mapi f filename]
195 maps through the lines of [filename] from top to bottom and then
196 reverse the output list.
197 [f] is NOT given the last lines of the file first
198 *)
199
200 val lines_map_and_fold_i :
201 ('a -> string -> int -> 'a * 'b) -> 'a -> string -> 'a * 'b list
202 (**
203 The usual fold_map with a counter on the lines of the given file
204 *)
205
206 (**
207 cover more compatibilty than Filename.concat
208 *)
209 val concat : string -> string -> string
210
211 (**
212 [output filename content]
213 returns [true] if everything ok,
214 returns [false] in case of a [Sys_error]
215
216 @deprecated This function is unefficient because
217 it allocate a big string just to print it in a file.
218 Use [pp_output] or [oc_output].
219 *)
220 val output : string -> string -> bool
221
222 (**
223 Like [output] but with a format interface.
224 <!> Unlike [output], the error message is returned
225
226 [pp_output filename printer data]
227 returns [None] if everything ok,
228 returns [Some error] in case of a [Sys_error]
229 *)
230 val pp_output : string -> (BaseFormat.formatter -> 'a -> unit) -> 'a -> string option
231
232 (**
233 Like [pp_output] but with a out_channel interface.
234
235 [oc_output filename printer data]
236 returns [None] if everything ok,
237 returns [Some error] in case of a [Sys_error]
238 *)
239 val oc_output : string -> (out_channel -> 'a -> unit) -> 'a -> string option
240
241 val mkdtemp : string -> string
242 val check_create_path : ?rights:Unix.file_perm -> string -> bool
243 val mlstate_dir : string Lazy.t
244 val mlstatelibs : string Lazy.t
245 val is_regular : string -> bool
246 val is_directory : string -> bool
247
248 (** {6 Directory Iterators} *)
249
250 (**
251 The function are executed in the current working directory.
252 [name] is the basename of the file
253 [path] is the relative path wrt to the given path, complete,
254 containing also the given path as prefix, and the filename.
255
256 Example:
257 let's say you have this tree in your current wd:
258 $ tree
259 toto/
260 foo.t
261 bar.g
262 foobar.gogo
263
264 you'll iter on:
265 [
266 name:"foo.t" path:"toto/foo.t" ;
267 name:"bar.g" path:"toto/bar.g" ;
268 name:foobar.gogo path:"foobar.gogo" ;
269 ]
270 Order of iter is unspecified
271 *)
272
273 (**
274 Iter also on directories if [showdir] is set to [true].
275 *)
276 val iter_dir_rec :
277 ?showdir:bool ->
278 (name:string -> path:string -> unit) -> string -> unit
279
280 (**
281 <!> Beware, the implementation contains a FIXME
282 *)
283 val fold_dir_rec :
284 ('a -> name:string -> path:string -> 'a) -> 'a -> string -> 'a
285
286 (**
287 Ignoring directories, iter only on regular files.
288 *)
289 val iter_dir :
290 (name:string -> path:string -> unit) -> string -> unit
291
292 (**
293 Ignoring directories, fold only on regular files.
294 <!> Beware, the implementation contains a FIXME
295 *)
296 val fold_dir :
297 ('a -> name:string -> path:string -> 'a) -> 'a -> string -> 'a
298
299 (**
300 [remove_rec file] behaves like [rm -rf file]
301 @raise Invalid_argument if [remove_rec] encounters a character or a
302 block device
303 *)
304 val remove_rec : string -> unit
305
306 (** {6 Sadly undocumented API} *)
307
308 val completion : string -> string list
309 val backup_path : string -> string option
310 val append_or_create : string -> out_channel
311 val channel_contents : in_channel -> string
312 exception Process_error of string
313 val process_output : string -> string
314 val simplify_path : string -> string
978b7c4 @akoprow [fix] typo: occurence->occurrence, occured->occurred
akoprow authored
315 (* return completed paths for filename fname for each occurrence in dirs *)
fccc685 Initial open-source release
MLstate authored
316
317 val get_locations_regexp : ?dir:bool -> string list (*dirs*) -> string (*filename:caml regexp*) -> string list (* fnames *)
318 val get_locations : ?dir:bool -> string list (*dirs*) -> string (*fname*) -> string list (* fnames *)
319 (* if dir, looks for a directory, else for a regular file. Defaults to [false] *)
320 (* same as get_locations but return only one path,
321 user can specilaised behavior in case of no or many possibl paths *)
322 val get_one_location :
323 ?dir:bool -> (* same meaning as for [get_locations] *)
324 ?missing_file : (string list (*dirs*) -> string (*fname*) -> string) ->
325 ?many_files : (string list (*dirs*) -> string (*fname*) -> string list (* paths *) -> string) ->
326 string list (*dirs*) -> string (*fname*) -> string
Something went wrong with that request. Please try again.