Fix auto-restore of automatic backup on DB corruption error
This commit is contained in:
parent
013dc958b3
commit
61452a835b
|
@ -37,6 +37,7 @@ Zotero.DBConnection = function(dbName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.MAX_BOUND_PARAMETERS = 999;
|
this.MAX_BOUND_PARAMETERS = 999;
|
||||||
|
this.DB_CORRUPTION_STRING = "2152857611";
|
||||||
|
|
||||||
Components.utils.import("resource://gre/modules/Sqlite.jsm", this);
|
Components.utils.import("resource://gre/modules/Sqlite.jsm", this);
|
||||||
|
|
||||||
|
@ -893,7 +894,7 @@ Zotero.DBConnection.prototype.integrityCheck = Zotero.Promise.coroutine(function
|
||||||
|
|
||||||
|
|
||||||
Zotero.DBConnection.prototype.checkException = function (e) {
|
Zotero.DBConnection.prototype.checkException = function (e) {
|
||||||
if (e.name && e.name == 'NS_ERROR_FILE_CORRUPTED') {
|
if (e.message.includes(this.DB_CORRUPTION_STRING)) {
|
||||||
// Write corrupt marker to data directory
|
// Write corrupt marker to data directory
|
||||||
var file = Zotero.File.pathToFile(Zotero.DataDirectory.getDatabase(this._dbName, 'is.corrupt'));
|
var file = Zotero.File.pathToFile(Zotero.DataDirectory.getDatabase(this._dbName, 'is.corrupt'));
|
||||||
Zotero.File.putContents(file, '');
|
Zotero.File.putContents(file, '');
|
||||||
|
@ -1173,16 +1174,16 @@ Zotero.DBConnection.prototype._getConnectionAsync = Zotero.Promise.coroutine(fun
|
||||||
catchBlock: try {
|
catchBlock: try {
|
||||||
var corruptMarker = Zotero.File.pathToFile(Zotero.DataDirectory.getDatabase(this._dbName, 'is.corrupt'));
|
var corruptMarker = Zotero.File.pathToFile(Zotero.DataDirectory.getDatabase(this._dbName, 'is.corrupt'));
|
||||||
if (corruptMarker.exists()) {
|
if (corruptMarker.exists()) {
|
||||||
throw {
|
throw new Error(this.DB_CORRUPTION_STRING);
|
||||||
name: 'NS_ERROR_FILE_CORRUPTED'
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
this._connection = yield Zotero.Promise.resolve(this.Sqlite.openConnection({
|
this._connection = yield Zotero.Promise.resolve(this.Sqlite.openConnection({
|
||||||
path: file.path
|
path: file.path
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (e.name=='NS_ERROR_FILE_CORRUPTED') {
|
Zotero.logError(e);
|
||||||
|
|
||||||
|
if (e.message.includes(this.DB_CORRUPTION_STRING)) {
|
||||||
this._debug("Database file '" + file.leafName + "' corrupted", 1);
|
this._debug("Database file '" + file.leafName + "' corrupted", 1);
|
||||||
|
|
||||||
// No backup file! Eek!
|
// No backup file! Eek!
|
||||||
|
@ -1204,7 +1205,11 @@ Zotero.DBConnection.prototype._getConnectionAsync = Zotero.Promise.coroutine(fun
|
||||||
corruptMarker.remove(null);
|
corruptMarker.remove(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
alert(Zotero.getString('db.dbCorruptedNoBackup', fileName));
|
Zotero.alert(
|
||||||
|
null,
|
||||||
|
Zotero.getString('startupError'),
|
||||||
|
Zotero.getString('db.dbCorruptedNoBackup', fileName)
|
||||||
|
);
|
||||||
break catchBlock;
|
break catchBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1230,7 +1235,11 @@ Zotero.DBConnection.prototype._getConnectionAsync = Zotero.Promise.coroutine(fun
|
||||||
path: file.path
|
path: file.path
|
||||||
}));
|
}));
|
||||||
|
|
||||||
alert(Zotero.getString('db.dbRestoreFailed', fileName));
|
Zotero.alert(
|
||||||
|
null,
|
||||||
|
Zotero.getString('general.error'),
|
||||||
|
Zotero.getString('db.dbRestoreFailed', fileName)
|
||||||
|
);
|
||||||
|
|
||||||
if (corruptMarker.exists()) {
|
if (corruptMarker.exists()) {
|
||||||
corruptMarker.remove(null);
|
corruptMarker.remove(null);
|
||||||
|
@ -1257,12 +1266,15 @@ Zotero.DBConnection.prototype._getConnectionAsync = Zotero.Promise.coroutine(fun
|
||||||
path: file
|
path: file
|
||||||
}));
|
}));
|
||||||
this._debug('Database restored', 1);
|
this._debug('Database restored', 1);
|
||||||
var msg = Zotero.getString('db.dbRestored', [
|
Zotero.alert(
|
||||||
fileName,
|
null,
|
||||||
Zotero.Date.getFileDateString(backupFile),
|
Zotero.getString('general.warning'),
|
||||||
Zotero.Date.getFileTimeString(backupFile)
|
Zotero.getString('db.dbRestored', [
|
||||||
]);
|
fileName,
|
||||||
alert(msg);
|
Zotero.Date.getFileDateString(backupFile),
|
||||||
|
Zotero.Date.getFileTimeString(backupFile)
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
if (corruptMarker.exists()) {
|
if (corruptMarker.exists()) {
|
||||||
corruptMarker.remove(null);
|
corruptMarker.remove(null);
|
||||||
|
|
|
@ -571,9 +571,9 @@ ingester.lookup.error = An error occurred while performing lookup for this ite
|
||||||
|
|
||||||
db.dbCorrupted = The Zotero database '%S' appears to have become corrupted.
|
db.dbCorrupted = The Zotero database '%S' appears to have become corrupted.
|
||||||
db.dbCorrupted.restart = Please restart %S to attempt an automatic restore from the last backup.
|
db.dbCorrupted.restart = Please restart %S to attempt an automatic restore from the last backup.
|
||||||
db.dbCorruptedNoBackup = The Zotero database '%S' 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.dbCorruptedNoBackup = The Zotero database '%S' appears to have become corrupted, and no automatic backup is available.\n\nA new database file has been created. The damaged file was saved to your Zotero data directory.
|
||||||
db.dbRestored = The Zotero database '%1$S' appears to have become corrupted.\n\nYour data was restored from the last automatic backup made on %2$S at %3$S. The damaged file was saved in your Zotero directory.
|
db.dbRestored = The Zotero database '%1$S' appears to have become corrupted.\n\nYour data was restored from the last automatic backup made on %2$S at %3$S. The damaged file was saved to your Zotero data directory.
|
||||||
db.dbRestoreFailed = The Zotero database '%S' 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.
|
db.dbRestoreFailed = The Zotero database '%S' 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 to your Zotero data directory.
|
||||||
|
|
||||||
db.integrityCheck.passed = No errors were found in the database.
|
db.integrityCheck.passed = No errors were found in the database.
|
||||||
db.integrityCheck.failed = Errors were found in your Zotero database.
|
db.integrityCheck.failed = Errors were found in your Zotero database.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user