From c95ce030ba6d8517751d3a4a1834ee81b5820a83 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 2 Dec 2008 07:50:24 +0000 Subject: [PATCH] Work around createUnique() brokenness on Windows (fixed in Fx3.0.5, but that's a couple weeks off) that was causing schema upgrade errors --- chrome/content/zotero/xpcom/schema.js | 44 +++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 84780225a..4c02d4238 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -1835,9 +1835,25 @@ Zotero.Schema = new function(){ 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); + try { + target.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644); + newName = target.leafName; + } + catch (e) { + // DEBUG: Work around createUnique() brokenness on Windows + // as of Fx3.0.4 (https://bugzilla.mozilla.org/show_bug.cgi?id=452217) + // + // We just delete the conflicting file + if (Zotero.isWin && e.name == 'NS_ERROR_FILE_ACCESS_DENIED') { + target.remove(true); + } + else { + throw (e); + } + } + if (newName) { + target.remove(false); + } } orphan.file.moveTo(orphaned, newName); movedFiles37[orphan.id] = orphan.file; @@ -2095,9 +2111,25 @@ Zotero.Schema = new function(){ 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); + try { + target.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644); + newName = target.leafName; + } + catch (e) { + // DEBUG: Work around createUnique() brokenness on Windows + // as of Fx3.0.4 (https://bugzilla.mozilla.org/show_bug.cgi?id=452217) + // + // We just delete the conflicting file + if (Zotero.isWin && e.name == 'NS_ERROR_FILE_ACCESS_DENIED') { + target.remove(true); + } + else { + throw (e); + } + } + if (newName) { + target.remove(false); + } } orphan.file.moveTo(orphaned, newName); movedFiles46[orphan.id] = orphan.file;