Skip to content

Commit 71a1f58

Browse files
committed
Workaround OCaml PR#8857 in Path.touch
Signed-off-by: David Allsopp <david.allsopp@metastack.com>
1 parent e156482 commit 71a1f58

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/stdune/path.ml

+13-3
Original file line numberDiff line numberDiff line change
@@ -1195,9 +1195,19 @@ let touch ?(create = true) p =
11951195
| In_build_dir k ->
11961196
Kind.to_string (Kind.append_local (Fdecl.get Build.build_dir) k)
11971197
in
1198-
try Unix.utimes p 0.0 0.0
1199-
with Unix.Unix_error (Unix.ENOENT, _, _) ->
1200-
if create then Unix.close (Unix.openfile p [ Unix.O_CREAT ] 0o777)
1198+
let create =
1199+
if create then
1200+
fun () ->
1201+
Unix.close (Unix.openfile p [ Unix.O_CREAT ] 0o777)
1202+
else
1203+
Fun.id
1204+
in
1205+
try Unix.utimes p 0.0 0.0 with
1206+
| Unix.Unix_error (Unix.ENOENT, _, _) -> create ()
1207+
| Unix.Unix_error (Unix.EUNKNOWNERR 0, _, _)
1208+
when Sys.win32 && not (Sys.file_exists p) ->
1209+
(* OCaml PR#8857 *)
1210+
create ()
12011211

12021212
let compare x y =
12031213
match (x, y) with

0 commit comments

Comments
 (0)