diff --git a/CHANGES.md b/CHANGES.md index 98a0be3f6b2..8fc967a0d8c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) ------------------ diff --git a/bin/install_uninstall.ml b/bin/install_uninstall.ml index 3bde614f85a..7e31bdd82a6 100644 --- a/bin/install_uninstall.ml +++ b/bin/install_uninstall.ml @@ -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 (