From 4bfbd2396a579b390a2892a8eb3a8404a4f81ea1 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 7 May 2013 15:17:46 +0900 Subject: [PATCH] do integrity check when closing collection --- aqt/main.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/aqt/main.py b/aqt/main.py index 6b1f16707..73d334fa9 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -269,10 +269,17 @@ how to restore from a backup.""") if not self.closeAllCollectionWindows(): return self.maybeOptimize() + self.progress.start(immediate=True) + corrupt = self.col.db.scalar("pragma integrity_check") != "ok" + if corrupt: + showWarning(_("Your collection file appears to be corrupt. \ +This can happen when the file is copied or moved while Anki is open, or \ +when the collection is stored on a network or cloud drive. Please see \ +the manual for information on how to restore from an automatic backup.")) self.col.close() self.col = None - self.progress.start(immediate=True) - self.backup() + if not corrupt: + self.backup() self.progress.finish() return True @@ -314,7 +321,7 @@ how to restore from a backup.""") os.unlink(os.path.join(dir, file[1])) def maybeOptimize(self): - # has two weeks passed? + # have two weeks passed? if (intTime() - self.pm.profile['lastOptimize']) < 86400*14: return self.progress.start(label=_("Optimizing..."), immediate=True)