]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/http_getter/http_getter_map.ml
Initial revision
[helm.git] / helm / http_getter / http_getter_map.ml
index 9ee87618104003943e0f49484c7e98be736a1a0a..06699f1781a237153c489d950fc89e8ee6a8464c 100644 (file)
@@ -1,5 +1,7 @@
 (*
- *  Copyright (C) 2000, HELM Team.
+ * Copyright (C) 2003:
+ *    Stefano Zacchiroli <zack@cs.unibo.it>
+ *    for the HELM Team http://helm.cs.unibo.it/
  *
  *  This file is part of HELM, an Hypertextual, Electronic
  *  Library of Mathematics, developed at the Computer Science
@@ -21,7 +23,7 @@
  *  MA  02111-1307, USA.
  *
  *  For details, see the HELM World-Wide-Web page,
- *  http://cs.unibo.it/helm/.
+ *  http://helm.cs.unibo.it/
  *)
 
 exception Key_already_in of string;;
@@ -29,12 +31,15 @@ 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
 
-    initializer Gc.finalise Dbm.close db  (* close db on GC *)
+    val mutable db = open_dbm ()
+
+    (*initializer Gc.finalise Dbm.close db  (* close db on GC *)*)
 
     method add key value =
       self#doWriter (lazy (
@@ -60,9 +65,26 @@ 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;
+        List.iter
+          (fun ext ->
+            let file = dbname ^ ext in
+            if Sys.file_exists file then Sys.remove file)
+          [".dir"; ".pag"; ".db"];
+        db <- open_dbm ()
+      ))
+
+    method close =
+      self#doWriter (lazy (
+        Dbm.close db
       ))
 
   end