Skip to content

Commit cb3629a

Browse files
dra27rgrinberg
authored andcommitted
Workaround OCaml PR#8857 in Path.touch
Signed-off-by: David Allsopp <david.allsopp@metastack.com>
1 parent ac6d7cd commit cb3629a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ Unreleased
4646

4747
- Add support for instrumentation dependencies (#4210, fixes #3983, @nojb)
4848

49+
- Workaround incorrect exception raised by Unix.utimes (OCaml PR#8857) in
50+
Path.touch on Windows (#4223, @dra27)
51+
4952
2.8.2 (21/01/2021)
5053
------------------
5154

src/stdune/path.ml

+13-3
Original file line numberDiff line numberDiff line change
@@ -1176,9 +1176,19 @@ let touch ?(create = true) p =
11761176
| In_build_dir k ->
11771177
Kind.to_string (Kind.append_local (Fdecl.get Build.build_dir) k)
11781178
in
1179-
try Unix.utimes p 0.0 0.0
1180-
with Unix.Unix_error (Unix.ENOENT, _, _) ->
1181-
if create then Unix.close (Unix.openfile p [ Unix.O_CREAT ] 0o777)
1179+
let create =
1180+
if create then
1181+
fun () ->
1182+
Unix.close (Unix.openfile p [ Unix.O_CREAT ] 0o777)
1183+
else
1184+
Fun.id
1185+
in
1186+
try Unix.utimes p 0.0 0.0 with
1187+
| Unix.Unix_error (Unix.ENOENT, _, _) -> create ()
1188+
| Unix.Unix_error (Unix.EUNKNOWNERR 0, _, _)
1189+
when Sys.win32 && not (Sys.file_exists p) ->
1190+
(* OCaml PR#8857 *)
1191+
create ()
11821192

11831193
let compare x y =
11841194
match (x, y) with

0 commit comments

Comments
 (0)