diff --git a/CHANGES b/CHANGES index 308b672f8..a41fe9dc3 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,8 @@ the behavior of Lwt_io.with_temp_dir following symlinks to directories on Win32. (#883, Antonin Décimo) + * Support deleting symlinks on Windows during cleanup of Lwt_io.with_temp_dir (#886, Antonin Décimo) + * Lwt_react.S.l[2-6]_s used polymorphic equality which could cause errors when handling functional values. (#893, Jérôme Vouillon) diff --git a/src/unix/lwt_io.ml b/src/unix/lwt_io.ml index 667593011..5bb2e258c 100644 --- a/src/unix/lwt_io.ml +++ b/src/unix/lwt_io.ml @@ -1509,11 +1509,16 @@ let rec delete_recursively directory = Lwt.return () else let path = Filename.concat directory entry in - Lwt_unix.lstat path >>= fun stat -> - if stat.Lwt_unix.st_kind = Lwt_unix.S_DIR then - delete_recursively path - else - unlink path + Lwt_unix.lstat path >>= fun {Lwt_unix.st_kind; _} -> + match st_kind with + | S_DIR -> delete_recursively path + | S_LNK when (Sys.win32 || Sys.cygwin) -> + Lwt_unix.stat path >>= fun {Lwt_unix.st_kind; _} -> + begin match st_kind with + | S_DIR -> Lwt_unix.rmdir path + | _ -> unlink path + end + | _ -> unlink path end >>= fun () -> Lwt_unix.rmdir directory