From 3fdb212dd603affad4666f58aa66a8b6576d6d0e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 22 Oct 2008 07:45:27 +0000 Subject: [PATCH] Fix for some attachment directories not being properly migrated to keys Also migrates remaining files for past upgrades on the trunk (assuming their ids haven't been changed by syncing--if the item that has a given id already has a directory or if there is no attachment item with that id, the directory will be moved to orphaned-files) --- chrome/content/zotero/xpcom/schema.js | 124 +++++++++++++++++++++++--- userdata.sql | 2 +- 2 files changed, 114 insertions(+), 12 deletions(-) diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index e971b5d22..e1bfff249 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -1791,18 +1791,14 @@ Zotero.Schema = new function(){ for each(var row in rows) { keys[row.itemID] = row.key; } - Zotero.debug(keys); if (storage37.exists()) { var entries = storage37.directoryEntries; - while (entries.hasMoreElements()) { - var file = entries.getNext(); - file.QueryInterface(Components.interfaces.nsILocalFile); - Zotero.debug("Directory is " + file.leafName); + entries.QueryInterface(Components.interfaces.nsIDirectoryEnumerator); + var file; + var renameQueue = []; + while (file = entries.nextFile) { var id = parseInt(file.leafName); - Zotero.debug(id); - Zotero.debug(file.isDirectory()); if (!file.isDirectory() || file.leafName != id) { - Zotero.debug("Skipping " + id); continue; } if (keys[id]) { @@ -1822,8 +1818,11 @@ Zotero.Schema = new function(){ } renameTarget.moveTo(orphaned, newName); } - file.moveTo(null, keys[id]); - moveReport += keys[id] + ' ' + id + "\n"; + renameQueue.push({ + id: id, + file: file, + key: keys[id] + }); } else { if (!orphaned.exists()) { @@ -1838,9 +1837,18 @@ Zotero.Schema = new function(){ target.remove(null); } file.moveTo(orphaned, newName); + movedFiles37[id] = file; } - movedFiles37[id] = file; } + entries.close(); + + for each(var dir in renameQueue) { + Zotero.debug("Moving " + dir.file.leafName + " to " + dir.key); + dir.file.moveTo(null, dir.key); + moveReport += dir.key + ' ' + dir.id + "\n"; + movedFiles37[dir.id] = dir.file; + } + if (moveReport) { moveReport = 'The following directory names in storage were changed:\n' + '------------------------------------------------------\n' @@ -1955,6 +1963,92 @@ Zotero.Schema = new function(){ if (i==43) { Zotero.DB.query("UPDATE itemNotes SET note='
' || TEXT2HTML(note) || '
' WHERE note NOT LIKE '