let rename_to_tmp path_orig prefix suffix =
let dir_orig = Filename.dirname path_orig in
let rec inner left =
if left <= 0
then
failwith
(Printf.sprintf
"Filew.rename_to_tmp: can't rename file %S to temporary name (directory %S, prefix %S, suffix %S)"
path_orig dir_orig prefix suffix)
else
(let fn_tmp =
Printf.sprintf "%s%06i%s" prefix (Random.State.int prng 1000000)
suffix in
let path_tmp = Filename.concat dir_orig fn_tmp
in
if is_exists path_tmp
then inner (left - 1)
else (rename path_orig path_tmp; path_tmp))
in inner temp_create_tries