]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matitaDb.ml
version 0.7.1
[helm.git] / helm / matita / matitaDb.ml
index c5bdbf84befc7dcbf595ed0a5d633b348108acea..b5b64d46f1d958c7d9c02a48a099253bb3137176 100644 (file)
@@ -37,6 +37,7 @@ let instance =
 
 
 let xpointer_RE = Pcre.regexp "#.*$"
+let file_scheme_RE = Pcre.regexp "^file://"
 
 let clean_owner_environment () =
   let dbd = instance () in
@@ -65,10 +66,10 @@ let clean_owner_environment () =
     (fun uri ->
       let uri = Pcre.replace ~rex:xpointer_RE ~templ:"" uri in
       List.iter
-        (fun suffix -> 
-          (*prerr_endline ("unregistering " ^ uri ^ suffix);*)
-          Http_getter.unregister (uri ^ suffix))
-        
+        (fun suffix ->
+          try
+           MatitaMisc.safe_remove (Http_getter.resolve (uri ^ suffix))
+          with Http_getter_types.Key_not_found _ -> ())
         [""; ".body"; ".types"])
     owned_uris;
   List.iter (fun statement -> 
@@ -104,6 +105,7 @@ let create_owner_environment () =
          let status = Mysql.status dbd in
          match status with 
          | Mysql.StatusError Mysql.Table_exists_error -> ()
+         | Mysql.StatusError Mysql.Dup_keyname -> ()
          | Mysql.StatusError _ -> raise exn
          | _ -> ()
       ) statements
@@ -150,3 +152,15 @@ let remove_uri uri =
   with
     exn -> raise exn (* no errors should be accepted *)
 
+let xpointers_of_ind uri =
+  let dbd = instance () in
+  let name_tbl =  MetadataTypes.name_tbl () in
+  let query = sprintf 
+    "SELECT source FROM %s WHERE source LIKE '%s#xpointer%%'" name_tbl 
+      (Mysql.escape (UriManager.string_of_uri uri))
+  in
+  let rc = Mysql.exec dbd query in
+  let l = ref [] in
+  Mysql.iter rc (fun a ->  match a.(0) with None ->()|Some a -> l := a:: !l);
+  List.map UriManager.uri_of_string !l
+