Commit a8346a65 authored by POTTIER Francois's avatar POTTIER Francois

Added [IO.moving_away].

parent f4ed19bf
(* Input-output utilities. *)
(* ------------------------------------------------------------------------- *)
(* [try/finally]. *)
(* [try/finally] has the same semantics as in Java. *)
let try_finally action handler =
let result =
......@@ -14,6 +14,21 @@ let try_finally action handler =
handler();
result
(* ------------------------------------------------------------------------- *)
(* [moving_away filename action] moves the file [filename] away (if it exists),
performs [action], then moves the file back into place (if it was moved
away). *)
let moving_away filename action =
if Sys.file_exists filename then
let newname = filename ^ ".moved_by_menhir" in
Sys.rename filename newname;
try_finally action (fun () ->
Sys.rename newname filename
)
else
action()
(* ------------------------------------------------------------------------- *)
(* [exhaust channel] reads all of the data that's available on [channel].
It does not assume that the length of the data is known ahead of time.
......
(* Input-output utilities. *)
(* [try/finally] *)
(* [try/finally] has the same semantics as in Java. *)
val try_finally : (unit -> 'a) -> (unit -> unit) -> 'a
(* [moving_away filename action] moves the file [filename] away (if it exists),
performs [action], then moves the file back into place (if it was moved
away). *)
val moving_away: string -> (unit -> 'a) -> 'a
(* [exhaust channel] reads all of the data that's available on [channel].
It does not assume that the length of the data is known ahead of time.
It does not close the channel. *)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment