diff options
author | Florian Weimer <fw@deneb.enyo.de> | 2005-10-20 09:01:44 +0000 |
---|---|---|
committer | Florian Weimer <fw@deneb.enyo.de> | 2005-10-20 09:01:44 +0000 |
commit | 8f6b9e5a3d7c0ab5629e28e5a5bf4f410088e900 (patch) | |
tree | a3cae36f3dc9d5b0a9411b230b466fa92ee89eaf /lib | |
parent | 9143133157960a92e8d9137a837694933da1d243 (diff) |
r612@deneb: fw | 2005-10-13 22:01:34 +0200
lib/python/security_db.py (DB.refresh):
Add.
git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@2480 e39458fd-73e7-0310-bf30-c45bca0a0e42
Diffstat (limited to 'lib')
-rw-r--r-- | lib/python/security_db.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/python/security_db.py b/lib/python/security_db.py index f990c24a97..f45dadc4ce 100644 --- a/lib/python/security_db.py +++ b/lib/python/security_db.py @@ -33,6 +33,7 @@ import cStringIO import debian_support import glob import os +import os.path import re import sys import types @@ -90,6 +91,7 @@ class DB: """ def __init__(self, name, verbose=False): + self.name = name self.db = apsw.Connection(name) self.verbose = verbose @@ -105,9 +107,22 @@ class DB: 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. |