From 54fdab889ad3ad98b66f82fdbe16f8e5b8251da8 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 20 Jul 2017 07:28:07 -0700 Subject: [PATCH] [driver] do not complain if results directory is empty Summary: This enables workflows such as `infer_out="$(mktemp -d --tmpdir infer-out-XXXXXX)" && infer -o "$infer_out" -- ...`. Reviewed By: mbouaziz Differential Revision: D5461176 fbshipit-source-id: a9ed8ef --- infer/src/backend/infer.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 175d4d5cd..dce97cb67 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -60,7 +60,9 @@ let assert_results_dir advice = L.setup_log_file () let remove_results_dir () = - if Sys.is_directory Config.results_dir = `Yes then ( + (* Look if file exists, it may not be a directory but that will be caught by the call to [is_results_dir]. If it's an empty directory, leave it alone. This allows users to create a temporary directory for the infer results without infer removing it to recreate it, which could be racy. *) + if Sys.file_exists Config.results_dir = `Yes && not (Utils.directory_is_empty Config.results_dir) + then ( 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@\nERROR: Please delete '%s' and try again@."