Fix deletion method for old DB backups on schema update
This commit is contained in:
parent
d03d54b396
commit
c9618b8a08
1 changed files with 23 additions and 10 deletions
|
@ -132,17 +132,30 @@ Zotero.Schema = new function(){
|
||||||
// Upgrade seems to have been a success -- delete any previous backups
|
// Upgrade seems to have been a success -- delete any previous backups
|
||||||
var maxPrevious = dbVersion - 1;
|
var maxPrevious = dbVersion - 1;
|
||||||
var file = Zotero.getZoteroDirectory();
|
var file = Zotero.getZoteroDirectory();
|
||||||
// directoryEntries.hasMoreElements() throws an error (possibly
|
var toDelete = [];
|
||||||
// because of the temporary SQLite journal file?), so we just look
|
try {
|
||||||
// for all versions
|
var files = file.directoryEntries;
|
||||||
for (var i=maxPrevious; i>=28; i--) {
|
while (files.hasMoreElements()) {
|
||||||
var fileName = 'zotero.sqlite.' + i + '.bak';
|
var file = files.getNext();
|
||||||
file.append(fileName);
|
file.QueryInterface(Components.interfaces.nsIFile);
|
||||||
if (file.exists()) {
|
if (file.isDirectory()) {
|
||||||
Zotero.debug('Removing previous backup file ' + fileName);
|
continue;
|
||||||
file.remove(null);
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue