From 3c7eec94560a82239e10fb67108dfc6095f2e545 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Tue, 25 Oct 2016 16:49:08 -0500 Subject: [PATCH] raise error if database is newer --- lbrynet/lbrynet_daemon/Daemon.py | 10 ++++++---- lbrynet/lbrynet_daemon/DaemonServer.py | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 37edc9429..b84eeba3e 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -981,10 +981,10 @@ class Daemon(jsonrpc.JSONRPC): self.startup_status = STARTUP_STAGES[1] log.info("Loading databases...") if self.created_data_dir: - db_revision = open(os.path.join(self.db_dir, "db_revision"), mode='w') - db_revision.write(str(self.current_db_revision)) - db_revision.close() - log.debug("Created the db revision file: %s", str(os.path.join(self.db_dir, "db_revision"))) + db_revision_path = os.path.join(self.db_dir, "db_revision") + with open(db_revision_path, mode='w') as db_revision: + db_revision.write(str(self.current_db_revision)) + log.debug("Created the db revision file: %s", db_revision_path) if not os.path.exists(self.blobfile_dir): os.mkdir(self.blobfile_dir) log.debug("Created the blobfile directory: %s", str(self.blobfile_dir)) @@ -994,6 +994,8 @@ class Daemon(jsonrpc.JSONRPC): db_revision_file = os.path.join(self.db_dir, "db_revision") if os.path.exists(db_revision_file): old_revision = int(open(db_revision_file).read().strip()) + if old_revision > self.current_db_revision: + raise Exception('This version of lbrynet is not compatible with the database') if old_revision < self.current_db_revision: from lbrynet.db_migrator import dbmigrator log.info("Upgrading your databases...") diff --git a/lbrynet/lbrynet_daemon/DaemonServer.py b/lbrynet/lbrynet_daemon/DaemonServer.py index 39268f5bd..99119618b 100644 --- a/lbrynet/lbrynet_daemon/DaemonServer.py +++ b/lbrynet/lbrynet_daemon/DaemonServer.py @@ -30,7 +30,8 @@ class DaemonServer(object): self.root.putChild(API_ADDRESS, self._api) return defer.succeed(True) - def start(self, branch=DEFAULT_UI_BRANCH, user_specified=False, branch_specified=False, wallet=None): + def start(self, branch=DEFAULT_UI_BRANCH, user_specified=False, + branch_specified=False, wallet=None): d = self._setup_server(wallet) d.addCallback(lambda _: self._api.setup(branch, user_specified, branch_specified)) return d