]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matitaInterpreter.ml
better owner hadling
[helm.git] / helm / matita / matitaInterpreter.ml
index 640b7406ee17f925832f864d410f7e95fb5b233c..88e44ea7a017012ab8387f692743a238e516e696 100644 (file)
@@ -256,6 +256,21 @@ let inddef_of_ast params indTypes (disambiguator:MatitaTypes.disambiguator) =
 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
@@ -286,7 +301,9 @@ let
   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 *)
@@ -297,6 +314,7 @@ let
     (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)