Skip to content

Commit fc345f5

Browse files
committed
Remove delete_recursively and win32_unlink
Looks like this was copied from Lwt at some point. It is not used within obuilder currently, nor have I found it used in any of our other projects. And it has since been exposed in Lwt. See https://github.com/ocsigen/lwt/blob/48abed72467ca7479e95f1be06d02f40c7c434bd/CHANGES#L25
1 parent e7d788e commit fc345f5

File tree

1 file changed

+0
-48
lines changed

1 file changed

+0
-48
lines changed

lib/os.ml

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -232,54 +232,6 @@ let rm ~directory =
232232
Log.warn (fun f -> f "Failed to remove %s because %s" directory m);
233233
Lwt.return_unit
234234

235-
(** delete_recursively code taken from Lwt. *)
236-
237-
let win32_unlink fn =
238-
Lwt.catch
239-
(fun () -> Lwt_unix.unlink fn)
240-
(function
241-
| Unix.Unix_error (Unix.EACCES, _, _) as ex ->
242-
Lwt_unix.lstat fn >>= fun {st_perm; _} ->
243-
(* Try removing the read-only attribute *)
244-
Lwt_unix.chmod fn 0o666 >>= fun () ->
245-
Lwt.catch
246-
(fun () -> Lwt_unix.unlink fn)
247-
(function _ ->
248-
(* Restore original permissions *)
249-
Lwt_unix.chmod fn st_perm >>= fun () ->
250-
Lwt.reraise ex)
251-
| ex -> Lwt.reraise ex)
252-
253-
let unlink =
254-
if Sys.win32 then
255-
win32_unlink
256-
else
257-
Lwt_unix.unlink
258-
259-
(* This is likely VERY slow for directories with many files. That is probably
260-
best addressed by switching to blocking calls run inside a worker thread,
261-
i.e. with Lwt_preemptive. *)
262-
let rec delete_recursively directory =
263-
Lwt_unix.files_of_directory directory
264-
|> Lwt_stream.iter_s begin fun entry ->
265-
if entry = Filename.current_dir_name ||
266-
entry = Filename.parent_dir_name then
267-
Lwt.return ()
268-
else
269-
let path = Filename.concat directory entry in
270-
Lwt_unix.lstat path >>= fun {Lwt_unix.st_kind; _} ->
271-
match st_kind with
272-
| S_DIR -> delete_recursively path
273-
| S_LNK when (Sys.win32 || Sys.cygwin) ->
274-
Lwt_unix.stat path >>= fun {Lwt_unix.st_kind; _} ->
275-
begin match st_kind with
276-
| S_DIR -> Lwt_unix.rmdir path
277-
| _ -> unlink path
278-
end
279-
| _ -> unlink path
280-
end >>= fun () ->
281-
Lwt_unix.rmdir directory
282-
283235
let normalise_path root_dir =
284236
if Sys.win32 then
285237
let vol, _ = Fpath.(v root_dir |> split_volume) in

0 commit comments

Comments
 (0)