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.
This commit is contained in:
Dan Stillman 2006-10-23 20:46:04 +00:00
parent 666831748e
commit 61fab3a2dd
2 changed files with 12 additions and 4 deletions

View File

@ -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);

View File

@ -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