From 61fab3a2ddf4285c29cb19b3dbc5eeb831e52f51 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 23 Oct 2006 20:46:04 +0000 Subject: [PATCH] Fixes #366, Automated backup will back up a corrupted DB We already copy to an interim temp file on shutdown--just try to open it before overwriting old backup file Still wish there was a way to detect corruption while Zotero was still open and pretending to write to the DB, but I don't know of one (other than making a copy of the DB and trying to open it, but as far as I can tell we can't release the file handle on it to then delete it or check again later)...will keep working on it. --- chrome/content/zotero/xpcom/zotero.js | 14 +++++++++++--- chrome/locale/en-US/zotero/zotero.properties | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index e4d9cc27b..0830f0d8a 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -186,9 +186,6 @@ var Zotero = new function(){ /* * Back up the main database file - * - * This could probably create a corrupt file fairly easily if all changes - * haven't been flushed to disk -- proceed with caution */ function backupDatabase(){ if (Zotero.DB.transactionInProgress()){ @@ -216,6 +213,17 @@ var Zotero = new function(){ throw (e); } + try { + var store = Components.classes["@mozilla.org/storage/service;1"]. + getService(Components.interfaces.mozIStorageService); + + var connection = store.openDatabase(tmpFile); + } + catch (e){ + Zotero.debug("Database file is corrupt--skipping backup"); + return false; + } + // Remove old backup file if (backupFile.exists()){ backupFile.remove(null); diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 40859ccd4..a8daf6942 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -178,7 +178,7 @@ ingester.scrapeError = Could Not Save Item. ingester.scrapeErrorDescription = An error occurred while saving this item. Please try again. If this error persists, contact the translator author. db.dbCorruptedNoBackup = The Zotero database appears to have become corrupted, and no automatic backup is available.\n\nA new database file has been created. The damaged file was saved in your Zotero directory. -db.dbRestored = The Zotero database appears to have become corrupted.\n\nYour data was restored from the last automatic backup made on %1$s at %2$s. The damaged file was saved in your Zotero directory. +db.dbRestored = The Zotero database appears to have become corrupted.\n\nYour data was restored from the last automatic backup made on %1$S at %2$S. The damaged file was saved in your Zotero directory. db.dbRestoreFailed = The Zotero database appears to have become corrupted, and an attempt to restore from the last automatic backup failed.\n\nA new database file has been created. The damaged file was saved in your Zotero directory. zotero.preferences.status.positionChange = Position change will take effect in new windows only