From 27804bb47c23a3387ab6a1112e14ea084bbe3535 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 30 Sep 2014 23:14:02 -0400 Subject: [PATCH] Fix database backup on userdata upgrade Also uncomment standard backup age tests --- chrome/content/zotero/xpcom/db.js | 9 ++++++--- chrome/content/zotero/xpcom/schema.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index 3909e7dc0e..f69a6e4212 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -624,6 +624,9 @@ Zotero.DBConnection.prototype.executeTransaction = Zotero.Promise.coroutine(func Zotero.DBConnection.prototype.waitForTransaction = function () { + if (!this._transactionPromise) { + return Zotero.Promise.resolve(); + } Zotero.debug("Waiting for transaction to finish"); return this._transactionPromise.then(function () { Zotero.debug("Done waiting for transaction"); @@ -955,7 +958,7 @@ Zotero.DBConnection.prototype.backupDatabase = Zotero.Promise.coroutine(function } } - if (Zotero.locked) { + if (Zotero.locked && !force) { this._debug("Zotero is locked -- skipping backup of DB '" + this._dbName + "'", 2); return false; } @@ -987,7 +990,7 @@ Zotero.DBConnection.prototype.backupDatabase = Zotero.Promise.coroutine(function var file = Zotero.getZoteroDatabase(this._dbName); // For standard backup, make sure last backup is old enough to replace - /*if (!suffix && !force) { + if (!suffix && !force) { var backupFile = Zotero.getZoteroDatabase(this._dbName, 'bak'); if (yield OS.File.exists(backupFile.path)) { var currentDBTime = (yield OS.File.stat(file.path)).lastModificationDate; @@ -1006,7 +1009,7 @@ Zotero.DBConnection.prototype.backupDatabase = Zotero.Promise.coroutine(function return; } } - }*/ + } this._debug("Backing up database '" + this._dbName + "'"); diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index a66af7fb82..da99d6a599 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -99,7 +99,7 @@ Zotero.Schema = new function(){ // If upgrading userdata, make backup of database first .then(function (schemaVersion) { if (userdata < schemaVersion) { - return Zotero.DB.backupDatabase(userdata); + return Zotero.DB.backupDatabase(userdata, true); } }) .then(function () {