Skip to content

Commit

Permalink
Workaround OCaml PR#8857 in Path.touch
Browse files Browse the repository at this point in the history
Signed-off-by: David Allsopp <[email protected]>
  • Loading branch information
dra27 authored and rgrinberg committed Feb 17, 2021
1 parent ac6d7cd commit cb3629a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Unreleased

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

- Workaround incorrect exception raised by Unix.utimes (OCaml PR#8857) in
Path.touch on Windows (#4223, @dra27)

2.8.2 (21/01/2021)
------------------

Expand Down
16 changes: 13 additions & 3 deletions src/stdune/path.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1176,9 +1176,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
Expand Down

0 comments on commit cb3629a

Please sign in to comment.