Under Windows, one needs to remove the original file before renaming the temporary one, or one gets Sys_error("File exists"). Before removing the original file, one needs to close the in-channel (which is a good idea anyway), or one gets Sys_error("foo.ml: Permission denied")
We currently use locally:
let ic = open_in path in
try
indent_channel ic args config out;
close_in ic;
match out, need_move with
| Some src, Some dst -> Sys.remove dst; Sys.rename src dst
| _, _ -> ()
with e ->
close_in ic; raise e
but this should be improved to avoid the double-close when an error is raised by Sys.remove or Sys.rename.
Under Windows, one needs to remove the original file before renaming the temporary one, or one gets Sys_error("File exists"). Before removing the original file, one needs to close the in-channel (which is a good idea anyway), or one gets Sys_error("foo.ml: Permission denied")
We currently use locally:
but this should be improved to avoid the double-close when an error is raised by Sys.remove or Sys.rename.