struct
(** General function for creating temporary files or directories in a parent directory with some permissions and with a prefix and suffix for the name. The function returns the name of the created file or directory. *) |
let rec temp_name ~(dir:bool) ~(perm:Unix.file_perm) ~(parent:string) ~(prefix:string) ~(suffix:string) () =
begin
let rnd = Random.int (1024*1024*1023) in
let candidate = (Filename.concat parent (prefix^(string_of_int rnd)^suffix)) in
if (Sys.file_exists candidate) then (temp_name ~dir ~perm ~parent ~prefix ~suffix ())
else
begin
if dir then (Unix.mkdir candidate perm)
else (touch candidate ~perm) ;
candidate
end
end
;;
end