Skip to content

Commit 5736b99

Browse files
authored
Refactor: use copy_file in install/uninstall (#6150)
This refactors `copy_file` in `Install_uninstall` so that it uses `Artifact_substitution.copy_file`. This ensures that these copies are atomic at least for non-special files. It also allows hooks to trigger on install (#6137). Signed-off-by: Etienne Millon <me@emillon.org> Signed-off-by: Etienne Millon <me@emillon.org>
1 parent 2f863bd commit 5736b99

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
- odoc rules now about `ODOC_SYNTAX` and will re-run accordingly (#6010, fixes
5454
#1117, @emillon)
5555

56+
- dune install: copy files in an atomic way (#6150, @emillon)
57+
5658
3.4.1 (26-07-2022)
5759
------------------
5860

bin/install_uninstall.ml

+17-14
Original file line numberDiff line numberDiff line change
@@ -303,20 +303,23 @@ module File_ops_real (W : Workspace) : File_operations = struct
303303
let copy_file ~src ~dst ~executable ~special_file ~package
304304
~(conf : Dune_rules.Artifact_substitution.conf) =
305305
let chmod = if executable then fun _ -> 0o755 else fun _ -> 0o644 in
306-
let ic, oc = Io.setup_copy ~chmod ~src ~dst () in
307-
Fiber.finalize
308-
~finally:(fun () ->
309-
Io.close_both (ic, oc);
310-
Fiber.return ())
311-
(fun () ->
312-
match (special_file : Special_file.t option) with
313-
| Some META -> copy_special_file ~src ~package ~ic ~oc ~f:process_meta
314-
| Some Dune_package ->
315-
copy_special_file ~src ~package ~ic ~oc
316-
~f:(process_dune_package ~get_location:conf.get_location)
317-
| None ->
318-
Dune_rules.Artifact_substitution.copy ~conf ~input_file:src
319-
~input:(input ic) ~output:(output oc))
306+
match (special_file : Special_file.t option) with
307+
| Some sf ->
308+
let ic, oc = Io.setup_copy ~chmod ~src ~dst () in
309+
Fiber.finalize
310+
~finally:(fun () ->
311+
Io.close_both (ic, oc);
312+
Fiber.return ())
313+
(fun () ->
314+
let f =
315+
match sf with
316+
| META -> process_meta
317+
| Dune_package ->
318+
process_dune_package ~get_location:conf.get_location
319+
in
320+
copy_special_file ~src ~package ~ic ~oc ~f)
321+
| None ->
322+
Dune_rules.Artifact_substitution.copy_file ~conf ~src ~dst ~chmod ()
320323

321324
let remove_file_if_exists dst =
322325
if Path.exists dst then (

0 commit comments

Comments
 (0)