Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Temp_file.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
(* Work with temporary files *) open Testo_util open Fpath_.Operators module P = Promise let with_temp_file ?contents ?(persist = false) ?(prefix = "testo-") ?(suffix = "") ?temp_dir func = let path = Filename_.temp_file ?temp_dir prefix suffix in P.protect (fun () -> (match contents with | None -> () | Some data -> Helpers.write_file path data); func path) ~finally:(fun () -> if not persist then Sys.remove !!path; P.return ())