From d19d8d3b5adcd9618ce668a91c1a8d26c27dd27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Thu, 8 Dec 2005 19:11:20 +0000 Subject: [PATCH] * implement db version file --- pisi/__init__.py | 2 ++ pisi/cli/commands.py | 4 ++++ pisi/lockeddbshelve.py | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/pisi/__init__.py b/pisi/__init__.py index d6f427c2..564e85bb 100644 --- a/pisi/__init__.py +++ b/pisi/__init__.py @@ -14,6 +14,8 @@ __version__ = "1.0_beta4" +__dbversion__ = "1.0" + __all__ = [ 'api', 'config', 'packagedb', 'installdb', 'search' ] class Exception(Exception): diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 75d9375f..83a5ae50 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -666,6 +666,10 @@ If package specs are given, they should be the names of package dirs under /var/ os.unlink(pisi.util.join_path(ctx.config.db_dir(), db)) self.init(database=True) self.rebuild_db() + verfn = join_path(pisi.context.config.db_dir(), 'dbversion') + verfile = file(verfn, 'w') + verfile.write(pisi.__dbversion__) + verfile.close() self.finalize() diff --git a/pisi/lockeddbshelve.py b/pisi/lockeddbshelve.py index 4b7cd935..4a533c2a 100644 --- a/pisi/lockeddbshelve.py +++ b/pisi/lockeddbshelve.py @@ -28,6 +28,7 @@ import pisi import pisi.context as ctx from pisi.util import join_path +from pisi.version import Version class Error(pisi.Error): pass @@ -35,12 +36,35 @@ class Error(pisi.Error): def init_dbenv(): ctx.dbenv = dbobj.DBEnv() - ctx.dbenv.open(pisi.context.config.db_dir(), - db.DB_CREATE | # allow db to create files - db.DB_INIT_MPOOL | # cache - db.DB_INIT_TXN | # transaction subsystem - db.DB_INIT_LOG | # logging subsystem - db.DB_RECOVER) # run normal recovery + flags = (db.DB_INIT_MPOOL | # cache + db.DB_INIT_TXN | # transaction subsystem + db.DB_INIT_LOG ) # logging subsystem + if os.access(pisi.context.config.db_dir(), os.R_OK): + # try to read version + verfn = join_path(pisi.context.config.db_dir(), 'dbversion') + if os.path.exists(verfn): + verfile = file(verfn, 'r') + ls = verfile.readlines() + currver = Version(ls[0]) + dbver = Version(pisi.__dbversion__) + if currver < dbver: + raise Error(_('Database version insufficient. Please run rebuild-db command.')) + elif currver > dbver: + raise Error(_('Database version greater than PiSi version. You need a newer PiSi.')) + else: + if os.access(pisi.context.config.db_dir(), os.W_OK): + ctx.ui.warning(_('Writing current database version')) + verfile = file(verfn, 'w') + verfile.write(pisi.__dbversion__) + verfile.close() + else: + raise Error(_('Cannot attain write access to database environment')) + else: + raise Error(_('Cannot attain read access to database environment')) + if os.access(pisi.context.config.db_dir(), os.W_OK): + flags |= (db.DB_RECOVER | # run normal recovery + db.DB_CREATE) # allow db to create files + ctx.dbenv.open(pisi.context.config.db_dir(), flags) #def open(filename, flags='r', mode = 0644, filetype = db.DB_BTREE): # db = LockedDBShelf(None, mode, filetype, None, True)