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
db.integrity_check()
# migrate database
db.migrate()
......
......@@ -2462,8 +2462,7 @@ class ConfigMigrator(Config):
sickrage.app.log.info("Backing up config before upgrade")
if not backup_versioned_file(sickrage.app.config_file, current_version):
sickrage.app.log.exit("Config backup failed, abort upgrading config")
sys.exit(1)
sickrage.app.log.fatal("Config backup failed, abort upgrading config")
else:
sickrage.app.log.info("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":
sickrage.app.log.fatal("{} database file {} is damaged, please restore a backup"
" or delete the database file and restart SiCKRAGE".format(self.name.capitalize(), 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)
sys.exit(1)
def close(self, *args, **kwargs):
logging.shutdown()
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