diff --git a/infer/src/base/DBWriter.mli b/infer/src/base/DBWriter.mli index 5e62bf530..a5798226f 100644 --- a/infer/src/base/DBWriter.mli +++ b/infer/src/base/DBWriter.mli @@ -35,7 +35,7 @@ val merge_dbs : infer_out_src:string -> unit val canonicalize : unit -> unit (** put the database on disk in deterministic form *) -val reset_capture_tables : unit -> unit [@@warning "-32"] +val reset_capture_tables : unit -> unit val start : unit -> unit diff --git a/infer/src/base/ResultsDir.ml b/infer/src/base/ResultsDir.ml index 4393afa5e..a12d3f84f 100644 --- a/infer/src/base/ResultsDir.ml +++ b/infer/src/base/ResultsDir.ml @@ -34,6 +34,24 @@ let non_empty_directory_exists results_dir = Sys.is_directory results_dir = `Yes && not (Utils.directory_is_empty results_dir) +let dirs_to_clean ~cache_capture = + let open Config in + let common_list = + [backend_stats_dir_name; classnames_dir_name; frontend_stats_dir_name; reporting_stats_dir_name] + in + if cache_capture then common_list + else captured_dir_name :: racerd_issues_dir_name :: starvation_issues_dir_name :: common_list + + +let delete_capture_and_results_data () = + DBWriter.reset_capture_tables () ; + let dirs_to_delete = + List.map ~f:(Filename.concat Config.results_dir) (dirs_to_clean ~cache_capture:true) + in + List.iter ~f:Utils.rmtree dirs_to_delete ; + () + + let remove_results_dir () = if non_empty_directory_exists Config.results_dir then ( if not Config.force_delete_results_dir then diff --git a/infer/src/base/ResultsDir.mli b/infer/src/base/ResultsDir.mli index 9a5edfd57..e8ad4bf90 100644 --- a/infer/src/base/ResultsDir.mli +++ b/infer/src/base/ResultsDir.mli @@ -15,3 +15,10 @@ val remove_results_dir : unit -> unit val create_results_dir : unit -> unit (** Create the results dir and sets up logging, the database, etc. *) + +val delete_capture_and_results_data : unit -> unit + [@@warning "-32"] +(** delete capture and results data in the results directory *) + +val dirs_to_clean : cache_capture:bool -> string list +(** directories in the results directory containing capture or results data *) diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index 21206bbfb..86fe953c6 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -81,17 +81,7 @@ let clean_results_dir () = ResultsDatabase.db_close () ; (* In Buck flavors mode we keep all capture data, but in Java mode we keep only the tenv *) let should_delete_dir = - let dirs_to_delete = - let open Config in - let common_list = - [ backend_stats_dir_name - ; classnames_dir_name - ; frontend_stats_dir_name - ; reporting_stats_dir_name ] - in - if cache_capture then common_list - else captured_dir_name :: racerd_issues_dir_name :: starvation_issues_dir_name :: common_list - in + let dirs_to_delete = ResultsDir.dirs_to_clean ~cache_capture in List.mem ~equal:String.equal dirs_to_delete in let should_delete_file =