Try removing the RO bit when unlinking files on Windows (#849)
Try removing the RO bit when unlinking files on Windows (#849)

* Try removing the RO bit when unlinking files on Windows

On Windows, some programs may set the read-only bit on files. For
instance, git marks its index files as read-only. Calling
`Unix.unlink` on such a file will result in an
`Unix.Unix_error(Unix.EACCES, "unlink", _)` exception.

`Lwt_io.with_temp_dir` creates a temporary directory in which it is
possible that a read-only file is created. In such case, the
`delete_recursively` function will not be able to clean the temporary
directory and will also raise an exception.

This patch allows by setting the file writable (removing the RO bit)
to delete the file.

This code was copied from Dune:
https://github.com/ocaml/dune/blob/ed361ebc4f37a81d3e6ffc905b0d45f61bc17e9c/otherlibs/stdune-unstable/fpath.ml#L74-L88

* Use Lwt.catch instead of try-with and restore perms if unlink fails
ocsigen/lwt,ocsigen/lwt,c-cube/lwt,c-cube/lwt,c-cube/lwt,ocsigen/lwt