3975: Accessing an incompatible database corrupts the database
svn: r16212
This commit is contained in:
@ -67,6 +67,29 @@ class DbVersionError(Exception):
|
|||||||
"Gramps.\nPlease upgrade to the corresponding version or use "
|
"Gramps.\nPlease upgrade to the corresponding version or use "
|
||||||
"XML for porting data between different database versions.")
|
"XML for porting data between different database versions.")
|
||||||
|
|
||||||
|
class DbEnvironmentError(Exception):
|
||||||
|
"""
|
||||||
|
Error used to report that the database 'environment' could not be opened.
|
||||||
|
Most likely, the database was created by a different version of the underlying database engine.
|
||||||
|
"""
|
||||||
|
def __init__(self, msg):
|
||||||
|
Exception.__init__(self)
|
||||||
|
self.msg = msg
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return (_("Gramps has detected an problem in opening the 'environment' "
|
||||||
|
"of the underlying Berkeley database. The most likely cause "
|
||||||
|
"is that the database was created with an old version "
|
||||||
|
"of the Berkeley database, and you are now using a new version. "
|
||||||
|
"It is quite likely that your database has not been "
|
||||||
|
"changed by Gramps.\nIf possible, you could revert to your "
|
||||||
|
"old version of Gramps and its support software; export "
|
||||||
|
"your database to XML; close the database; then upgrade again "
|
||||||
|
"to this version "
|
||||||
|
"and import the XML file. Alternatively, it may be possible "
|
||||||
|
"to upgrade your database.")
|
||||||
|
+ '\n\n' + str(self.msg))
|
||||||
|
|
||||||
class DbUpgradeRequiredError(Exception):
|
class DbUpgradeRequiredError(Exception):
|
||||||
"""
|
"""
|
||||||
Error used to report that a database needs to be upgraded before it can be
|
Error used to report that a database needs to be upgraded before it can be
|
||||||
|
@ -52,7 +52,7 @@ from sys import maxint
|
|||||||
from gen.lib import (GenderStats, Person, Family, Event, Place, Source,
|
from gen.lib import (GenderStats, Person, Family, Event, Place, Source,
|
||||||
MediaObject, Repository, Note, Tag)
|
MediaObject, Repository, Note, Tag)
|
||||||
from gen.db import (DbBsddbRead, DbWriteBase, BSDDBTxn,
|
from gen.db import (DbBsddbRead, DbWriteBase, BSDDBTxn,
|
||||||
DbTxn, BsddbBaseCursor, DbVersionError,
|
DbTxn, BsddbBaseCursor, DbVersionError, DbEnvironmentError,
|
||||||
DbUpgradeRequiredError, find_surname, find_surname_name,
|
DbUpgradeRequiredError, find_surname, find_surname_name,
|
||||||
DbUndoBSDDB as DbUndo)
|
DbUndoBSDDB as DbUndo)
|
||||||
from gen.db.dbconst import *
|
from gen.db.dbconst import *
|
||||||
@ -402,13 +402,17 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
|||||||
db.DB_INIT_MPOOL | db.DB_INIT_LOCK |\
|
db.DB_INIT_MPOOL | db.DB_INIT_LOCK |\
|
||||||
db.DB_INIT_LOG | db.DB_INIT_TXN | db.DB_THREAD
|
db.DB_INIT_LOG | db.DB_INIT_TXN | db.DB_THREAD
|
||||||
|
|
||||||
# As opposed to before, we always try recovery on databases
|
|
||||||
env_flags |= db.DB_RECOVER
|
|
||||||
|
|
||||||
# Environment name is now based on the filename
|
# Environment name is now based on the filename
|
||||||
env_name = name
|
env_name = name
|
||||||
|
|
||||||
self.env.open(env_name, env_flags)
|
try:
|
||||||
|
self.env.open(env_name, env_flags)
|
||||||
|
except Exception, msg:
|
||||||
|
try:
|
||||||
|
self.__close_early()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
raise DbEnvironmentError(msg)
|
||||||
self.env.txn_checkpoint()
|
self.env.txn_checkpoint()
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
@ -1724,7 +1728,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
|||||||
if version < 15:
|
if version < 15:
|
||||||
upgrade.gramps_upgrade_15(self)
|
upgrade.gramps_upgrade_15(self)
|
||||||
|
|
||||||
print "Upgrade time:", int(time.time()-t), "seconds"
|
_LOG.debug("Upgrade time: %d seconds" % int(time.time()-t))
|
||||||
|
|
||||||
def set_auto_remove(self):
|
def set_auto_remove(self):
|
||||||
"""
|
"""
|
||||||
|
@ -312,6 +312,10 @@ class DbLoader(CLIDbLoader):
|
|||||||
except gen.db.exceptions.DbVersionError, msg:
|
except gen.db.exceptions.DbVersionError, msg:
|
||||||
self.dbstate.no_database()
|
self.dbstate.no_database()
|
||||||
self._errordialog( _("Cannot open database"), str(msg))
|
self._errordialog( _("Cannot open database"), str(msg))
|
||||||
|
except gen.db.exceptions.DbEnvironmentError, msg:
|
||||||
|
_LOG.error("dbloader: read_file: DbEnvironmentError detected")
|
||||||
|
self.dbstate.no_database()
|
||||||
|
self._errordialog( _("Cannot open database"), str(msg))
|
||||||
except OSError, msg:
|
except OSError, msg:
|
||||||
self.dbstate.no_database()
|
self.dbstate.no_database()
|
||||||
self._errordialog(
|
self._errordialog(
|
||||||
|
Reference in New Issue
Block a user