OCamlPro / ocp-indent

Indentation tool for OCaml, to be used from editors like Emacs and Vim.
http://www.typerex.org/ocp-indent.html
Other
200 stars 63 forks source link

--replace not working under Windows #217

Open alainfrisch opened 8 years ago

alainfrisch commented 8 years ago

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.