[minor] small readability improvements

Summary: Random edits made while reading ZipLib.ml. They're really not interesting, sorry...

Reviewed By: sblackshear

Differential Revision: D7686159

fbshipit-source-id: 19ef1ce
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent a4a1a9c55e
commit 507ba9493c

@ -2835,15 +2835,14 @@ let specs_library =
match infer_cache with match infer_cache with
| Some cache_dir when use_jar_cache -> | Some cache_dir when use_jar_cache ->
let add_spec_lib specs_library filename = let add_spec_lib specs_library filename =
let key_dir =
let basename = Filename.basename filename in let basename = Filename.basename filename in
let key = basename ^ Utils.string_crc_hex32 filename in let key = basename ^ Utils.string_crc_hex32 filename in
let key_dir = cache_dir ^/ key in cache_dir ^/ key
in
let extract_specs dest_dir filename = let extract_specs dest_dir filename =
if Filename.check_suffix filename ".jar" then if Filename.check_suffix filename ".jar" then (
match Unix.mkdir dest_dir ~perm:0o700 with (try Unix.mkdir dest_dir ~perm:0o700 with Unix.Unix_error _ -> ()) ;
| exception Unix.Unix_error _ ->
()
| () ->
let zip_channel = Zip.open_in filename in let zip_channel = Zip.open_in filename in
let entries = Zip.entries zip_channel in let entries = Zip.entries zip_channel in
let extract_entry (entry: Zip.entry) = let extract_entry (entry: Zip.entry) =
@ -2852,7 +2851,7 @@ let specs_library =
Zip.copy_entry_to_file zip_channel entry dest_file Zip.copy_entry_to_file zip_channel entry dest_file
in in
List.iter ~f:extract_entry entries ; List.iter ~f:extract_entry entries ;
Zip.close_in zip_channel Zip.close_in zip_channel )
in in
extract_specs key_dir filename ; key_dir :: specs_library extract_specs key_dir filename ; key_dir :: specs_library
in in

@ -31,8 +31,8 @@ let load_from_cache serializer zip_path cache_dir zip_library =
DB.filename_from_string to_path DB.filename_from_string to_path
in in
match deserialize (extract absolute_path) with match deserialize (extract absolute_path) with
| Some data -> | Some _ as data ->
Some data data
| None -> | None ->
None None
| exception Caml.Not_found -> | exception Caml.Not_found ->
@ -69,26 +69,27 @@ let zip_libraries =
{models; zip_filename; zip_channel= lazy (Zip.open_in zip_filename)} {models; zip_filename; zip_channel= lazy (Zip.open_in zip_filename)}
in in
let zip_libs = let zip_libs =
if Config.use_jar_cache && Config.infer_cache <> None then [] if Config.use_jar_cache && Option.is_some Config.infer_cache then []
else else
(* Order matters, jar files should appear in the order in which they should be searched for let load_zip fname =
specs files. Config.specs_library is in reverse order of appearance on command line. *)
let add_zip zip_libs fname =
if Filename.check_suffix fname ".jar" then if Filename.check_suffix fname ".jar" then
(* fname is a zip of specs *) (* fname is a zip of specs *)
mk_zip_lib false fname :: zip_libs Some (mk_zip_lib false fname)
else (* fname is a dir of specs *) else (* fname is a dir of specs *)
zip_libs None
in in
List.fold ~f:add_zip ~init:[] Config.specs_library (* Order matters: jar files should appear in the order in which they should be searched for
specs files. [Config.specs_library] is in reverse order of appearance on the command
line. *)
List.rev_filter_map Config.specs_library ~f:load_zip
in in
if Config.biabduction && not Config.models_mode && Sys.file_exists Config.models_jar = `Yes if Config.biabduction && not Config.models_mode && Sys.file_exists Config.models_jar = `Yes
then mk_zip_lib true Config.models_jar :: zip_libs then mk_zip_lib true Config.models_jar :: zip_libs
else zip_libs) else zip_libs)
(* Search path in the list of zip libraries and use a cache directory to save already (** Search path in the list of zip libraries and use a cache directory to save already deserialized
deserialized data *) data *)
let load serializer path = let load serializer path =
let rec loop = function let rec loop = function
| [] -> | [] ->

Loading…
Cancel
Save