From 6fe358ed3e0e87347ea06488ece404bdb5ce303b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Tue, 19 Jun 2012 17:54:13 +0200 Subject: [PATCH] Add some exception handling code for when the preferences backup file doesn't exist. --- src/calibre/library/restore.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/calibre/library/restore.py b/src/calibre/library/restore.py index fc0df4a006..597e877833 100644 --- a/src/calibre/library/restore.py +++ b/src/calibre/library/restore.py @@ -115,12 +115,18 @@ class Restore(Thread): self.progress_callback('Starting restore preferences', 0) dbpath = os.path.join(self.src_library_path, 'metadata_db_prefs.json') ndbpath = os.path.join(self.library_path, 'metadata_db_prefs.json') - shutil.copyfile(dbpath, ndbpath) - db = RestoreDatabase(self.library_path) - db.prefs.read_serialized(self.library_path) - db.commit() - db.conn.close() - self.progress_callback('Finished restore preferences', 1) + if not os.path.exists(dbpath): + self.progress_callback('Cannot restore preferences. Backup file not found.', 1) + return + try: + shutil.copyfile(dbpath, ndbpath) + db = RestoreDatabase(self.library_path) + db.prefs.read_serialized(self.library_path) + db.commit() + db.conn.close() + self.progress_callback('Finished restore preferences', 1) + except: + self.progress_callback('Restoring preferences failed', 1) def scan_library(self): for dirpath, dirnames, filenames in os.walk(self.src_library_path):