diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index b7af9ed97..8b360cc32 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -1796,6 +1796,7 @@ Zotero.Schema = new function(){ entries.QueryInterface(Components.interfaces.nsIDirectoryEnumerator); var file; var renameQueue = []; + var orphanQueue = []; while (file = entries.nextFile) { var id = parseInt(file.leafName); if (!file.isDirectory() || file.leafName != id) { @@ -1805,18 +1806,10 @@ Zotero.Schema = new function(){ var renameTarget = storage37.clone(); renameTarget.append(keys[id]); if (renameTarget.exists()) { - if (!orphaned.exists()) { - orphaned.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); - } - var target = orphaned.clone(); - target.append(keys[id]); - var newName = null; - if (target.exists()) { - target.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644); - newName = target.leafName; - target.remove(null); - } - renameTarget.moveTo(orphaned, newName); + orphanQueue.push({ + id: id, + file: renameTarget + }); } renameQueue.push({ id: id, @@ -1825,22 +1818,31 @@ Zotero.Schema = new function(){ }); } else { - if (!orphaned.exists()) { - orphaned.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); - } + orphanQueue.push({ + id: id, + file: file + }); + } + } + entries.close(); + + if (orphanQueue.length) { + if (!orphaned.exists()) { + orphaned.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); + } + for each(var orphan in orphanQueue) { var target = orphaned.clone(); - target.append(file.leafName); + target.append(orphan.file.leafName); var newName = null; if (target.exists()) { target.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644); newName = target.leafName; target.remove(null); } - file.moveTo(orphaned, newName); - movedFiles37[id] = file; + orphan.file.moveTo(orphaned, newName); + movedFiles37[orphan.id] = orphan.file; } } - entries.close(); for each(var dir in renameQueue) { Zotero.debug("Moving " + dir.file.leafName + " to " + dir.key); @@ -1964,92 +1966,6 @@ Zotero.Schema = new function(){ Zotero.DB.query("UPDATE itemNotes SET note='
' || TEXT2HTML(note) || '
' WHERE note NOT LIKE '