]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/http_getter/http_getter_map.ml
- added maps sync
[helm.git] / helm / http_getter / http_getter_map.ml
index 9ee87618104003943e0f49484c7e98be736a1a0a..7a5ed1a3bc93ca1490b607f7574bd65e78acffde 100644 (file)
  *  http://cs.unibo.it/helm/.
  *)
 
+let debug = true;;
+let debug_print s = if debug then prerr_endline s;;
+
 exception Key_already_in of string;;
 exception Key_not_found of string;;
 
 class map dbname =
   let perm = 420 in (* permission 644 in decimal notation *)
-  let db = Dbm.opendbm dbname [ Dbm.Dbm_rdwr; Dbm.Dbm_create ] perm in
+  let open_dbm () = Dbm.opendbm dbname [ Dbm.Dbm_rdwr; Dbm.Dbm_create ] perm in
+  
   object (self)
 
     inherit ThreadSafe.threadSafe
 
+    val mutable db = open_dbm ()
+
     initializer Gc.finalise Dbm.close db  (* close db on GC *)
 
     method add key value =
@@ -60,9 +66,18 @@ class map dbname =
         Dbm.iter f db
       ))
 
+    method sync =
+      self#doWriter (lazy (
+        Dbm.close db;
+        db <- open_dbm ()
+      ))
+
     method clear =
       self#doWriter (lazy (
-        Dbm.iter (fun k _ -> Dbm.remove db k) db
+        Dbm.close db;
+        Sys.remove (dbname ^ ".dir");
+        Sys.remove (dbname ^ ".pag");
+        db <- open_dbm ()
       ))
 
   end