Skip to content

Commit 86d940c

Browse files
committed
fix: pass O_SHARE_DELETE when digesting files
Fixes #8268 This flag corresponds to what `Stdlib.open_in` does. When passed, the files can be removed while they are still open. This condition can happen when background digests are enabled. This is a no-op everywhere else. This allows enabling background digests on Windows. Signed-off-by: Etienne Millon <me@emillon.org>
1 parent af53605 commit 86d940c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Unreleased
2424
- Improve `dune describe external-lib-deps` by adding the internal dependencies
2525
for more information. (#7478, @moyodiallo)
2626

27+
- Re-enable background file digests on Windows. The files are now open in a way
28+
that prevents race condition around deletion. (#8262, fixes #8268, @emillon)
29+
2730
3.9.2 (2023-07-25)
2831
------------------
2932

src/dune_config/config.ml

+1-4
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ let background_digests =
116116
let t =
117117
{ name = "background_digests"
118118
; of_string = Toggle.of_string
119-
; value =
120-
(match Platform.OS.value with
121-
| Linux -> `Enabled
122-
| _ -> `Disabled)
119+
; value = background_default
123120
}
124121
in
125122
register t;

src/dune_digest/dune_digest.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ end
1717

1818
module Direct_impl : Digest_impl = struct
1919
let file file =
20+
(* On Windows, if this function is invoked in a background thread,
21+
if can happen that the file is not properly closed.
22+
[O_SHARE_DELETE] ensures that the main thread can delete it even if it
23+
is still open. See #8243. *)
2024
let fd =
21-
match Unix.openfile file [ Unix.O_RDONLY ] 0 with
25+
match Unix.openfile file [ Unix.O_RDONLY; O_SHARE_DELETE ] 0 with
2226
| fd -> fd
2327
| exception Unix.Unix_error (Unix.EACCES, _, _) ->
2428
raise (Sys_error (sprintf "%s: Permission denied" file))

0 commit comments

Comments
 (0)