diff --git a/bin/forester/main.ml b/bin/forester/main.ml index 41875fa..a741f31 100644 --- a/bin/forester/main.ml +++ b/bin/forester/main.ml @@ -139,41 +139,6 @@ let theme_dir ~(config : Config.t) = None end -let mtime path = (EP.stat ~follow:true path).mtime - -let theme_dir_has_changed ~env ~(forest : State.t) theme_dir = - let rec dir_up_to_date src dst = - EP.is_directory dst - && - let sorted = List.sort compare in - let src_entries = sorted (EP.read_dir src) in - let dst_entries = sorted (EP.read_dir dst) in - src_entries = dst_entries - && List.for_all - (fun name -> entry_up_to_date EP.(src / name) EP.(dst / name)) - src_entries - and entry_up_to_date src dst = - if EP.is_directory src then dir_up_to_date src dst - else mtime src <= mtime dst - in - let visible_dir_entries dir = - List.filter - (fun name -> not (String.starts_with ~prefix:"." name)) - (EP.read_dir dir) - in - try - let cwd = Eio.Stdenv.cwd env in - let src = EP.(env#fs / theme_dir) in - let dst = Forester.output_path ~cwd ~forest in - if - EP.is_directory dst - && List.for_all - (fun name -> entry_up_to_date EP.(src / name) EP.(dst / name)) - (visible_dir_entries src) - then false - else true - with _ -> true - let build ~env ~sw _ config_path dev no_theme emit_legacy_xml = match Config_parser.parse_forest_config_file ~env config_path with | Error errors -> List.iter Error.print_config_error errors @@ -192,19 +157,22 @@ let build ~env ~sw _ config_path dev no_theme emit_legacy_xml = m "Build_forest: %.3fs" (Unix.gettimeofday () -. start)); (forest, pending_jobs) in - if not no_theme then begin - let@ theme_dir = Option.iter @~ theme_dir ~config in - if theme_dir_has_changed ~env ~forest theme_dir then - begin match Eio_util.path_of_dir ~env theme_dir with - | Ok path -> Forester.copy_contents_of_dir ~env ~forest path - | Error exn -> Error.(print ~config @@ io_error exn) - end - end; - Forester.render_forest ~progress:render_progress ~forest ~emit_legacy_xml (); + let theme_copied = + if no_theme then None + else + Option.map + (fun theme_dir -> + let@ () = Eio.Fiber.fork_promise ~sw in + match Eio_util.path_of_dir ~env theme_dir with + | Ok path -> Forester.copy_contents_of_dir ~env ~forest path + | Error exn -> Error.(print ~config @@ io_error exn)) + (theme_dir ~config) + in begin match Eio.Promise.await pending_jobs with | Ok () -> () | Error exn -> raise exn end; + Forester.render_forest ~progress:render_progress ~forest ~emit_legacy_xml (); finalise_progress_display (); Link_checker.check_and_report_all ~forest; let elapsed = Unix.gettimeofday () -. start_time in @@ -219,7 +187,8 @@ let build ~env ~sw _ config_path dev no_theme emit_legacy_xml = Logs.app (fun m -> m "Built %d tree%s%s in %.1fs" n_trees (if n_trees = 1 then "" else "s") - other_note elapsed) + other_note elapsed); + Option.iter Eio.Promise.await_exn theme_copied let new_tree ~env ~sw config_path dest_dir prefix template random = match Config_parser.parse_forest_config_file ~env config_path with diff --git a/lib/compiler/Eio_util.ml b/lib/compiler/Eio_util.ml index 2bbbc66..4583377 100644 --- a/lib/compiler/Eio_util.ml +++ b/lib/compiler/Eio_util.ml @@ -132,7 +132,7 @@ let copy_to_dir ~env ~cwd ~sources ~dest_dir = Path.mkdirs ~exists_ok:true ~perm:0o755 path; if Sys.unix then run_process ~quiet:true ~env ~cwd - (["cp"; "-r"; "-L"] @ sources @ [dest_dir]) + (["cp"; "-R"; "-L"; "-f"] @ sources @ [dest_dir]) else let@ source = List.iter @~ sources in run_process ~quiet:true ~env ~cwd ["xcopy"; source; dest_dir ^ "/"]