From 242b027db67d31d2abe7e9e392b1ad6e03413195 Mon Sep 17 00:00:00 2001 From: Michael Soegtrop <7895506+MSoegtropIMC@users.noreply.github.com> Date: Mon, 3 Feb 2025 12:02:44 +0100 Subject: [PATCH] Windows: retry a file remove - a virus checker might lock files Fixes #11425 Signed-off-by: Michael Soegtrop <7895506+MSoegtropIMC@users.noreply.github.com> --- otherlibs/stdune/src/fpath.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/otherlibs/stdune/src/fpath.ml b/otherlibs/stdune/src/fpath.ml index c9206c40667..4e3f3ca8fe7 100644 --- a/otherlibs/stdune/src/fpath.ml +++ b/otherlibs/stdune/src/fpath.ml @@ -118,7 +118,13 @@ let win32_unlink fn = Unix.chmod fn 0o666; Unix.unlink fn with - | _ -> raise e) + | _ -> + (* On Windows a virus scanner frequently has a lock on new executables for a short while - just retry *) + let rec retry_loop cnt = + Unix.sleep 1; + (try Unix.unlink fn + with _ -> if cnt>0 then retry_loop (cnt-1) else raise e) + in retry_loop 30) ;; let unlink_exn = if Stdlib.Sys.win32 then win32_unlink else Unix.unlink