From 71a1f583f1c709668f8ee1bd56ecbf94558dc270 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sat, 13 Feb 2021 11:26:08 +0000 Subject: [PATCH] Workaround OCaml PR#8857 in Path.touch Signed-off-by: David Allsopp --- src/stdune/path.ml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/stdune/path.ml b/src/stdune/path.ml index af3928e0fe36..4a6c74b94649 100644 --- a/src/stdune/path.ml +++ b/src/stdune/path.ml @@ -1195,9 +1195,19 @@ let touch ?(create = true) p = | In_build_dir k -> Kind.to_string (Kind.append_local (Fdecl.get Build.build_dir) k) in - try Unix.utimes p 0.0 0.0 - with Unix.Unix_error (Unix.ENOENT, _, _) -> - if create then Unix.close (Unix.openfile p [ Unix.O_CREAT ] 0o777) + let create = + if create then + fun () -> + Unix.close (Unix.openfile p [ Unix.O_CREAT ] 0o777) + else + Fun.id + in + try Unix.utimes p 0.0 0.0 with + | Unix.Unix_error (Unix.ENOENT, _, _) -> create () + | Unix.Unix_error (Unix.EUNKNOWNERR 0, _, _) + when Sys.win32 && not (Sys.file_exists p) -> + (* OCaml PR#8857 *) + create () let compare x y = match (x, y) with