[utils] `Utils.dir_is_empty` was always returning `false`

Summary:
oops_house

This was introduced when upgrading Core, as `Unix.readdir` became deprecated in
favour of `Unix.readdir_opt` but the exception-based logic was left unchanged.

Reviewed By: mbouaziz

Differential Revision: D5461353

fbshipit-source-id: c0994c3
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent a6632d8039
commit fb9cad4ea7

@ -156,18 +156,7 @@ let directory_iter f path =
in in
if Sys.is_directory path = `Yes then loop [path] else f path if Sys.is_directory path = `Yes then loop [path] else f path
let dir_is_empty path = let directory_is_empty path = Sys.readdir path |> Array.is_empty
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 string_crc_hex32 s = Digest.to_hex (Digest.string s) let string_crc_hex32 s = Digest.to_hex (Digest.string s)

@ -53,7 +53,7 @@ val directory_fold : ('a -> string -> 'a) -> 'a -> string -> 'a
val directory_iter : (string -> unit) -> string -> unit val directory_iter : (string -> unit) -> string -> unit
(** Functional iter function over all the file of a directory *) (** 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. *) (** 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 val read_json_file : string -> (Yojson.Basic.json, string) Result.t

@ -182,7 +182,7 @@ let check_captured_empty driver_mode =
let clean_command_opt = clean_compilation_command driver_mode in let clean_command_opt = clean_compilation_command driver_mode in
(* if merge is passed, the captured folder will be empty at this point, (* if merge is passed, the captured folder will be empty at this point,
but will be filled later on. *) 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 ( match clean_command_opt with
| Some clean_command | Some clean_command
-> L.user_warning "@\nNothing to compile. Try running `%s` first.@." clean_command -> L.user_warning "@\nNothing to compile. Try running `%s` first.@." clean_command

Loading…
Cancel
Save