Scan file tree: proceed in sequence

This commit is contained in:
Louis Gesbert 2023-09-11 17:16:35 +02:00
parent bf048f0a74
commit 94ec864890
3 changed files with 14 additions and 11 deletions

View File

@ -240,7 +240,7 @@ let get_lang file =
Option.bind (Re.exec_opt catala_suffix_regex file) @@ fun g ->
List.assoc_opt (Re.Group.get g 1) Cli.languages
let scan_tree (dir : File.t) : catala_build_item list =
let scan_tree (dir : File.t) : catala_build_item Seq.t =
File.scan_tree
(fun f ->
match get_lang f with
@ -602,7 +602,7 @@ let collect_in_folder
| Some (test_file_name, ninja) ->
ninja, test_file_names ^ " $\n " ^ test_file_name
in
List.fold_left
Seq.fold_left
(fun acc (file, lang) ->
let acc = collect collect_all_ninja_build acc file lang in
collect collect_inline_ninja_builds acc file lang)

View File

@ -132,17 +132,20 @@ let scan_tree f t =
false
in
let not_hidden t = match t.[0] with '.' | '_' -> false | _ -> true in
let rec do_dir acc d =
let items = Sys.readdir d |> Array.map (fun t -> d / t) |> Array.to_list in
do_files acc items
and do_files acc flist =
let rec do_dir d =
Sys.readdir d
|> Array.to_list
|> List.filter not_hidden
|> List.map (fun t -> d / t)
|> do_files
and do_files flist =
let dirs, files =
flist
|> List.filter not_hidden
|> List.sort (fun a b -> -compare a b)
|> List.partition is_dir
in
let acc = List.rev_append (List.filter_map f files) acc in
List.fold_left do_dir acc dirs
Seq.append
(Seq.concat (Seq.map do_dir (List.to_seq dirs)))
(Seq.filter_map f (List.to_seq files))
in
do_dir [] t
do_dir t

View File

@ -105,7 +105,7 @@ val format : Format.formatter -> t -> unit
(** Formats a filename in a consistent style, with double-quotes and color (when
the output supports) *)
val scan_tree : (t -> 'a option) -> t -> 'a list
val scan_tree : (t -> 'a option) -> t -> 'a Seq.t
(** Recursively scans a directory for files. Directories or files matching ".*"
or "_*" are ignored. Unreadable files or subdirectories are ignored with a
debug message. *)