From c9618b8a08f1ae96f6a06fd21229c291891ece2a Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 16 Apr 2009 10:30:55 +0000 Subject: [PATCH] Fix deletion method for old DB backups on schema update --- chrome/content/zotero/xpcom/schema.js | 33 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 200430c099..7213b3832b 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -132,17 +132,30 @@ Zotero.Schema = new function(){ // Upgrade seems to have been a success -- delete any previous backups var maxPrevious = dbVersion - 1; var file = Zotero.getZoteroDirectory(); - // directoryEntries.hasMoreElements() throws an error (possibly - // because of the temporary SQLite journal file?), so we just look - // for all versions - for (var i=maxPrevious; i>=28; i--) { - var fileName = 'zotero.sqlite.' + i + '.bak'; - file.append(fileName); - if (file.exists()) { - Zotero.debug('Removing previous backup file ' + fileName); - file.remove(null); + var toDelete = []; + try { + var files = file.directoryEntries; + while (files.hasMoreElements()) { + var file = files.getNext(); + file.QueryInterface(Components.interfaces.nsIFile); + if (file.isDirectory()) { + continue; + } + var matches = file.leafName.match(/zotero\.sqlite\.([0-9]{2,})\.bak/); + if (!matches) { + continue; + } + if (matches[1]>=28 && matches[1]<=maxPrevious) { + toDelete.push(file); + } } - file = file.parent; + for each(var file in toDelete) { + Zotero.debug('Removing previous backup file ' + file.leafName); + file.remove(false); + } + } + catch (e) { + Zotero.debug(e); } }