diff --git a/infer/src/base/Utils.ml b/infer/src/base/Utils.ml index 3828834d1..5d7a62cb9 100644 --- a/infer/src/base/Utils.ml +++ b/infer/src/base/Utils.ml @@ -156,18 +156,7 @@ let directory_iter f path = in if Sys.is_directory path = `Yes then loop [path] else f path -let dir_is_empty path = - let dir_handle = Unix.opendir path in - let is_empty = ref true in - ( try - while !is_empty do - if not - (Option.value_map (Unix.readdir_opt dir_handle) ~default:false - ~f:(List.mem ~equal:String.equal ["."; ".."])) - then is_empty := false - done - with End_of_file -> () ) ; - Unix.closedir dir_handle ; !is_empty +let directory_is_empty path = Sys.readdir path |> Array.is_empty let string_crc_hex32 s = Digest.to_hex (Digest.string s) diff --git a/infer/src/base/Utils.mli b/infer/src/base/Utils.mli index e620ae746..be634bc68 100644 --- a/infer/src/base/Utils.mli +++ b/infer/src/base/Utils.mli @@ -53,7 +53,7 @@ val directory_fold : ('a -> string -> 'a) -> 'a -> string -> 'a val directory_iter : (string -> unit) -> string -> unit (** Functional iter function over all the file of a directory *) -val dir_is_empty : string -> bool +val directory_is_empty : string -> bool (** Returns true if a given directory is empty. The directory is assumed to exist. *) val read_json_file : string -> (Yojson.Basic.json, string) Result.t diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index e6437cab9..b7615da9c 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -182,7 +182,7 @@ let check_captured_empty driver_mode = let clean_command_opt = clean_compilation_command driver_mode in (* if merge is passed, the captured folder will be empty at this point, but will be filled later on. *) - if Utils.dir_is_empty Config.captured_dir && not Config.merge then ( + if Utils.directory_is_empty Config.captured_dir && not Config.merge then ( ( match clean_command_opt with | Some clean_command -> L.user_warning "@\nNothing to compile. Try running `%s` first.@." clean_command