let
save_object_to_disk uri obj
=
+ let ensure_path_exists path =
+ let dir = Filename.dirname path in
+ try
+ let stats = Unix.stat dir in
+ if stats.Unix.st_kind <> Unix.S_DIR then
+ raise (Failure (dir ^ " already exists and is not a directory"))
+ else
+ ()
+ with
+ Unix.Unix_error (_,_,_) ->
+ let pstatus = Unix.system ("mkdir -p " ^ dir) in
+ match pstatus with
+ | Unix.WEXITED n when n = 0 -> ()
+ | _ -> raise (Failure ("Unable to create " ^ dir))
+ in
(* generate annobj, ids_to_inner_sorts and ids_to_inner_types *)
let annobj,_,_,ids_to_inner_sorts,ids_to_inner_types,_,_ =
Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
let path_scheme_of path = "file:/" ^ path in
(* now write to disk *)
+ ensure_path_exists innertypespath;
Xml.pp ~quiet:true xmlinnertypes (Some innertypespath) ;
+ ensure_path_exists xmlpath;
Xml.pp ~quiet:true xml (Some xmlpath) ;
(* now register to the getter *)
(match bodyxml,bodyuri with
None,None -> ()
| Some bodyxml,Some bodyuri->
+ ensure_path_exists xmlbodypath;
Xml.pp ~quiet:true bodyxml (Some xmlbodypath) ;
Http_getter.register' bodyuri (path_scheme_of xmlbodypath)
| _-> assert false)