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 committed Feb 13, 2021
1 parent e156482 commit 7498313
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 @@ -30,6 +30,9 @@ Unreleased

- Auto-detect `dune-project` files as `dune` files in Emacs (#4222, @shonfeder)

- 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 @@ -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
Expand Down

0 comments on commit 7498313

Please sign in to comment.