Commit 2a8a136b authored by echel0n's avatar echel0n

Added database integrity check, shuts down SR if corrupt database is detected.

Added fatal loggger function to log critical error and exit application.
parent 3079a6fc
......@@ -262,6 +262,9 @@ class Core(object):
# perform database startup actions
for db in [self.main_db, self.cache_db]:
# perform integrity check
# migrate database
......@@ -2462,8 +2462,7 @@ class ConfigMigrator(Config):"Backing up config before upgrade")
if not backup_versioned_file(, current_version):"Config backup failed, abort upgrading config")
sys.exit(1)"Config backup failed, abort upgrading config")
else:"Proceeding with upgrade")
......@@ -167,6 +167,12 @@ class SRDatabase(object):
except DatabaseNotControlledError:
return 0
def integrity_check(self):
if self.db_type == 'sqlite':
if self.session().scalar("PRAGMA integrity_check") != "ok":"{} database file {} is damaged, please restore a backup"
" or delete the database file and restart SiCKRAGE".format(, self.db_path))
def sync_db_repo(self):
if self.version < self.db_version:
if self.db_type == 'sqlite':
......@@ -233,5 +233,9 @@ class Logger(logging.getLoggerClass()):
def warning(self, msg, *args, **kwargs):
super(Logger, self).warning(msg, *args, **kwargs)
def fatal(self, msg, *args, **kwargs):
super(Logger, self).fatal(msg, *args, **kwargs)
def close(self, *args, **kwargs):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment