Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: use copy_file in install/uninstall #6150

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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