]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/getter/http_getter_map.ml
generate HTML templates using XSLT starting from a bunch of .src files
[helm.git] / helm / ocaml / getter / http_getter_map.ml
index 1b5d209d330a2ea8593830ffe530e6ce5d65314f..7c411d8317fc570ae8177c2246f18b2c7b3cb44c 100644 (file)
  *  http://helm.cs.unibo.it/
  *)
 
-exception Key_already_in of string;;
-exception Key_not_found of string;;
+open Http_getter_types
 
 class map dbname =
   let perm = 420 in (* permission 644 in decimal notation *)
-  let open_dbm () = Dbm.opendbm dbname [ Dbm.Dbm_rdwr; Dbm.Dbm_create ] perm in
+  let open_dbm () =
+    Http_getter_misc.mkdir ~parents:true (Filename.dirname dbname);
+    Dbm.opendbm dbname [ Dbm.Dbm_rdwr; Dbm.Dbm_create ] perm
+  in
   
   object (self)
 
@@ -46,7 +48,9 @@ class map dbname =
        theory:/path/t.theory into theory:/path/t/index.theory
        when cic:/path/t/ exists *)
     method private normalize_key key =
-     if Pcre.pmatch ~rex:index_RE key then
+     if Pcre.pmatch ~rex:index_RE key &&
+        (try ignore (Dbm.find db key); false with Not_found -> true)
+     then
       (* we substitute /index.theory with .theory *)
       String.sub key 0 (String.length key - 13) ^ ".theory"
      else key
@@ -54,19 +58,19 @@ class map dbname =
     method add key value =
       self#doWriter (lazy (
         try
-          Dbm.add db (self#normalize_key key) value
+          Dbm.add db key value
         with Dbm.Dbm_error "Entry already exists" -> raise (Key_already_in key)
       ))
 
     method replace key value =
       self#doWriter (lazy (
-        Dbm.replace db (self#normalize_key key) value
+        Dbm.replace db key value
       ))
 
     method remove key =
       self#doWriter (lazy (
         try
-          Dbm.remove db (self#normalize_key key)
+          Dbm.remove db key
         with Dbm.Dbm_error "dbm_delete" -> raise (Key_not_found key)
       ))