Reviewed By: sblackshear Differential Revision: D3269015 fb-gh-sync-id: 19d0438 fbshipit-source-id: 19d0438master
parent
0cda42fc90
commit
a352c0ffa8
@ -0,0 +1,65 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) 2016 - present Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*)
|
||||||
|
|
||||||
|
open! Utils
|
||||||
|
|
||||||
|
module L = Logging
|
||||||
|
|
||||||
|
|
||||||
|
let get_cache_dir infer_cache zip_filename =
|
||||||
|
let basename = Filename.basename zip_filename in
|
||||||
|
let key = basename ^ string_crc_hex32 zip_filename in
|
||||||
|
Filename.concat infer_cache key
|
||||||
|
|
||||||
|
let load_from_cache serializer zip_path cache_dir zip_library =
|
||||||
|
let absolute_path = Filename.concat cache_dir zip_path in
|
||||||
|
let deserialize = Serialization.from_file serializer in
|
||||||
|
let extract to_path =
|
||||||
|
if not (Sys.file_exists to_path) then
|
||||||
|
begin
|
||||||
|
DB.create_path (Filename.dirname to_path);
|
||||||
|
let zip_channel = Config.zip_channel zip_library in
|
||||||
|
let entry = Zip.find_entry zip_channel zip_path in
|
||||||
|
Zip.copy_entry_to_file zip_channel entry to_path
|
||||||
|
end;
|
||||||
|
DB.filename_from_string to_path in
|
||||||
|
match deserialize (extract absolute_path) with
|
||||||
|
| Some data when Config.is_models zip_library -> Some (data, DB.Models)
|
||||||
|
| Some data -> Some (data, DB.Spec_lib)
|
||||||
|
| None -> None
|
||||||
|
| exception Not_found -> None
|
||||||
|
|
||||||
|
let load_from_zip serializer zip_path zip_library =
|
||||||
|
let zip_channel = Config.zip_channel zip_library in
|
||||||
|
let deserialize = Serialization.from_string serializer in
|
||||||
|
match deserialize (Zip.read_entry zip_channel (Zip.find_entry zip_channel zip_path)) with
|
||||||
|
| Some data when Config.is_models zip_library -> Some (data, DB.Models)
|
||||||
|
| Some data -> Some (data, DB.Spec_lib)
|
||||||
|
| None -> None
|
||||||
|
| exception Not_found -> None
|
||||||
|
|
||||||
|
let load_data serializer path zip_library =
|
||||||
|
let zip_path = Filename.concat Config.default_in_zip_results_dir path in
|
||||||
|
match !Config.infer_cache with
|
||||||
|
| None ->
|
||||||
|
load_from_zip serializer zip_path zip_library
|
||||||
|
| Some infer_cache ->
|
||||||
|
let cache_dir = get_cache_dir infer_cache (Config.zip_filename zip_library) in
|
||||||
|
load_from_cache serializer zip_path cache_dir zip_library
|
||||||
|
|
||||||
|
(* Search path in the list of zip libraries and use a cache directory to save already
|
||||||
|
deserialized data *)
|
||||||
|
let load serializer path =
|
||||||
|
let rec loop = function
|
||||||
|
| [] -> None
|
||||||
|
| zip_library :: other_libraries ->
|
||||||
|
let opt = load_data serializer path zip_library in
|
||||||
|
if Option.is_some opt then opt
|
||||||
|
else loop other_libraries in
|
||||||
|
loop (Config.get_zip_libraries ())
|
@ -0,0 +1,13 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) 2016 - present Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*)
|
||||||
|
|
||||||
|
(** [load serializer path] searches for the file at the given path in the zip libraries.
|
||||||
|
If Config.infer_cache is set, already deserialized data will be saved there and [path]
|
||||||
|
will be searched from the cache first. *)
|
||||||
|
val load : 'a Serialization.serializer -> string -> ('a * DB.origin) option
|
Loading…
Reference in new issue