Add DB.paths_matching utility method to recursively search files under a directory matching a function f.

Reviewed By: sblackshear

Differential Revision: D3642877

fbshipit-source-id: 6a9fc4b
master
Lázaro Clapp Jiménez Labora 9 years ago committed by Facebook Github Bot 0
parent 3064caacdb
commit ed85a129f5

@ -369,3 +369,16 @@ let file_is_in_cpp_model file =
let normalized_file_dir = filename_to_absolute (Filename.dirname file) in
let normalized_cpp_models_dir = filename_to_absolute Config.cpp_models_dir in
string_is_prefix normalized_cpp_models_dir normalized_file_dir
(** Return all absolute paths recursively under root_dir, matching the given
matcher function f *)
let paths_matching root_dir f =
let rec paths path_list dir = Array.fold_left
(fun acc file ->
let p = Filename.concat dir file in
if Sys.is_directory p then (paths acc p)
else if f p then p :: acc
else acc)
path_list
(Sys.readdir dir) in
paths [] root_dir

@ -167,3 +167,6 @@ val is_source_file: string -> bool
(** Returns true if the file is a C++ model *)
val file_is_in_cpp_model : string -> bool
(** Return all file paths recursively under the given directory which match the given predicate *)
val paths_matching : string -> (string -> bool) -> string list

Loading…
Cancel
Save