[Secure-testing-commits] r2480 - lib/python

Florian Weimer fw at costa.debian.org
Thu Oct 20 09:01:45 UTC 2005


Author: fw
Date: 2005-10-20 09:01:44 +0000 (Thu, 20 Oct 2005)
New Revision: 2480

Modified:
   lib/python/security_db.py
Log:
 r612 at deneb:  fw | 2005-10-13 22:01:34 +0200
 lib/python/security_db.py (DB.refresh):
   Add.

Modified: lib/python/security_db.py
===================================================================
--- lib/python/security_db.py	2005-10-20 09:01:34 UTC (rev 2479)
+++ lib/python/security_db.py	2005-10-20 09:01:44 UTC (rev 2480)
@@ -33,6 +33,7 @@
 import debian_support
 import glob
 import os
+import os.path
 import re
 import sys
 import types
@@ -90,6 +91,7 @@
     """
 
     def __init__(self, name, verbose=False):
+        self.name = name
         self.db = apsw.Connection(name)
         self.verbose = verbose
 
@@ -105,9 +107,22 @@
                     print "DB: schema version mismatch: expected %d, got %d" \
                           % (self.schema_version, v)
                 raise SchemaMismatch, `v`
+            # Database has been created at this point.  Small race
+            # condition here (the already opened database might refer
+            # to an older file).
+            self.__stat = os.stat(self.name)
             return
         assert False
 
+    def refresh(self):
+        """Checks if the database file is still the same and reopens
+        it if necessary."""
+        current = os.stat(self.name)
+        if os.path.samestat(self.__stat, current):
+            return
+        self.__stat = current
+        self.db = apsw.Connection(self.name)
+
     def cursor(self):
         """Creates a new database cursor.
 




More information about the Secure-testing-commits mailing list