Skip to content

Commit

Permalink
Merge pull request #38 from moble/moble-patch-1
Browse files Browse the repository at this point in the history
Catch possible I/O error initializing trust DB
  • Loading branch information
minrk committed Jun 24, 2016
2 parents 116bffd + 94c76f5 commit 58032ff
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions nbformat/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,20 @@ def _db_default(self):
try:
db = sqlite3.connect(self.db_file, **kwargs)
self.init_db(db)
except sqlite3.DatabaseError:
old_db_location = os.path.join(self.data_dir, self.db_file + ".bak")
self.log.warn("""The signatures database cannot be opened; maybe it is corrupted or encrypted. You may need to rerun your notebooks to ensure that they are trusted to run Javascript. The old signatures database has been renamed to %s and a new one has been created.""",
old_db_location)
except (sqlite3.DatabaseError, sqlite3.OperationalError):
if self.db_file != ':memory:':
os.rename(self.db_file, self.db_file + u'.bak')
db = sqlite3.connect(self.db_file, **kwargs)
self.init_db(db)
old_db_location = os.path.join(self.data_dir, self.db_file + ".bak")
self.log.warn("""The signatures database cannot be opened; maybe it is corrupted or encrypted. You may need to rerun your notebooks to ensure that they are trusted to run Javascript. The old signatures database has been renamed to %s and a new one has been created.""",
old_db_location)
try:
os.rename(self.db_file, self.db_file + u'.bak')
db = sqlite3.connect(self.db_file, **kwargs)
self.init_db(db)
except (sqlite3.DatabaseError, sqlite3.OperationalError):
self.log.warn("""Failed commiting signatures database to disk. You may need to move the database file to a non-networked file system, using config option `NotebookNotary.db_file`. Using in-memory signatures database for the remainder of this session.""")
self.db_file = ':memory:'
db = sqlite3.connect(self.db_file, **kwargs)
self.init_db(db)
else:
raise
return db
Expand Down

0 comments on commit 58032ff

Please sign in to comment.