Skip to content

Commit

Permalink
Refactor: use copy_file in install/uninstall (#6150)
Browse files Browse the repository at this point in the history
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 <[email protected]>

Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon authored Sep 22, 2022
1 parent 2f863bd commit 5736b99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
- odoc rules now about `ODOC_SYNTAX` and will re-run accordingly (#6010, fixes
#1117, @emillon)

- dune install: copy files in an atomic way (#6150, @emillon)

3.4.1 (26-07-2022)
------------------

Expand Down
31 changes: 17 additions & 14 deletions bin/install_uninstall.ml
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,23 @@ module File_ops_real (W : Workspace) : File_operations = struct
let copy_file ~src ~dst ~executable ~special_file ~package
~(conf : Dune_rules.Artifact_substitution.conf) =
let chmod = if executable then fun _ -> 0o755 else fun _ -> 0o644 in
let ic, oc = Io.setup_copy ~chmod ~src ~dst () in
Fiber.finalize
~finally:(fun () ->
Io.close_both (ic, oc);
Fiber.return ())
(fun () ->
match (special_file : Special_file.t option) with
| Some META -> copy_special_file ~src ~package ~ic ~oc ~f:process_meta
| Some Dune_package ->
copy_special_file ~src ~package ~ic ~oc
~f:(process_dune_package ~get_location:conf.get_location)
| None ->
Dune_rules.Artifact_substitution.copy ~conf ~input_file:src
~input:(input ic) ~output:(output oc))
match (special_file : Special_file.t option) with
| Some sf ->
let ic, oc = Io.setup_copy ~chmod ~src ~dst () in
Fiber.finalize
~finally:(fun () ->
Io.close_both (ic, oc);
Fiber.return ())
(fun () ->
let f =
match sf with
| META -> process_meta
| Dune_package ->
process_dune_package ~get_location:conf.get_location
in
copy_special_file ~src ~package ~ic ~oc ~f)
| None ->
Dune_rules.Artifact_substitution.copy_file ~conf ~src ~dst ~chmod ()

let remove_file_if_exists dst =
if Path.exists dst then (
Expand Down

0 comments on commit 5736b99

Please sign in to comment.