[infer-out] Fix removing result directory

Summary:
It removed the result directory without check due to a bug. This diff fixes it to do the check and more careful removement of files.

* Before removing a result directory, it checks
  * if the directory is empty: This is ok.
  * if the directory is non-empty, but has `results.db`: This is ok, because the directory seems to be an infer's result directory.
  * if the directory is non-empty and no `results.db`: This is not ok, so it does not remove the directory.

Reviewed By: jvillard

Differential Revision: D26635059

fbshipit-source-id: fa808265f
master
Sungkeun Cho 4 years ago committed by Facebook GitHub Bot
parent 598cb10170
commit f15d6d9675

@ -80,9 +80,9 @@ module RunState = struct
store ()
end
let is_results_dir ~check_correct_version () =
let is_results_dir () =
let capture_db_path = get_path CaptureDB in
let has_all_markers = (not check_correct_version) || Sys.is_file capture_db_path = `Yes in
let has_all_markers = Sys.is_file capture_db_path = `Yes in
Result.ok_if_true has_all_markers ~error:(Printf.sprintf "'%s' not found" capture_db_path)
@ -96,7 +96,7 @@ let non_empty_directory_exists results_dir =
let remove_results_dir () =
if non_empty_directory_exists Config.results_dir then (
if (not Config.buck) && not Config.force_delete_results_dir then
Result.iter_error (is_results_dir ~check_correct_version:false ()) ~f:(fun err ->
Result.iter_error (is_results_dir ()) ~f:(fun err ->
L.(die UserError)
"ERROR: '%s' exists but does not seem to be an infer results directory: %s@\n\
ERROR: Please delete '%s' and try again@." Config.results_dir err Config.results_dir ) ;
@ -128,7 +128,7 @@ let create_results_dir () =
let assert_results_dir advice =
Result.iter_error (is_results_dir ~check_correct_version:true ()) ~f:(fun err ->
Result.iter_error (is_results_dir ()) ~f:(fun err ->
L.(die UserError)
"ERROR: No results directory at '%s': %s@\nERROR: %s@." Config.results_dir err advice ) ;
RunState.load_and_validate ()
@ -154,6 +154,4 @@ let scrub_for_caching () =
(* make sure we are done with the database *)
ResultsDatabase.db_close () ;
List.iter ~f:Utils.rmtree
( (* some versions of sqlite do not clean up after themselves *) (get_path CaptureDB ^ "-shm")
:: (get_path CaptureDB ^ "-wal")
:: ResultsDirEntryName.to_delete_before_caching_capture ~results_dir:Config.results_dir )
(ResultsDirEntryName.to_delete_before_caching_capture ~results_dir:Config.results_dir)

@ -12,6 +12,8 @@ let buck_infer_deps_file_name = "infer-deps.txt"
type id =
| AllocationTraces
| CaptureDB
| CaptureDBShm
| CaptureDBWal
| CaptureDependencies
| ChangedFunctions
| Debug
@ -69,6 +71,16 @@ let of_id = function
; kind= File
; before_incremental_analysis= Keep
; before_caching_capture= Keep }
| CaptureDBShm ->
{ rel_path= "results.db-shm"
; kind= File
; before_incremental_analysis= Keep
; before_caching_capture= Delete }
| CaptureDBWal ->
{ rel_path= "results.db-wal"
; kind= File
; before_incremental_analysis= Keep
; before_caching_capture= Delete }
| ChangedFunctions ->
{ rel_path= "changed_functions.json"
; kind= File

@ -12,6 +12,8 @@ open! IStd
type id =
| AllocationTraces (** directory for storing allocation traces *)
| CaptureDB (** the capture database *)
| CaptureDBShm (** SQLite-generated index file for the capture database's write-ahead log *)
| CaptureDBWal (** the capture database's write-ahead log generated by SQLite *)
| CaptureDependencies (** list of infer-out/ directories that contain capture artefacts *)
| ChangedFunctions (** results of the clang test determinator *)
| Debug (** directory containing debug data *)

Loading…
Cancel
Save