From 83781293dac221593b12df423e7adf7c6d089d9e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 1 Oct 2009 20:26:31 +0000 Subject: [PATCH] - Display more helpful message for "(NS_ERROR_FILE_ACCESS_DENIED) [nsIFile.remove]" error when a remotely modified file is in use locally on Windows - Fix a potential NS_ERROR_TARGET_FILE_EXISTS error from a recent commit - Fix alignment of sync error icon --- .../content/zotero-platform/mac/overlay.css | 5 +++++ chrome/content/zotero/xpcom/storage.js | 20 ++++++++++++++++--- chrome/content/zotero/xpcom/storage/zfs.js | 8 ++++++-- chrome/skin/default/zotero/overlay.css | 1 - 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero-platform/mac/overlay.css b/chrome/content/zotero-platform/mac/overlay.css index 6ae867d01..fafe83e69 100644 --- a/chrome/content/zotero-platform/mac/overlay.css +++ b/chrome/content/zotero-platform/mac/overlay.css @@ -57,6 +57,11 @@ -moz-padding-start: 8px; } +#zotero-tb-sync-warning[error=true] +{ + margin-bottom: 2px; +} + .zotero-tb-button[open="true"] > .toolbarbutton-icon, .zotero-tb-button:hover:active > .toolbarbutton-icon, #zotero-pane-stack[fullscreenmode="true"] #zotero-tb-fullscreen > .toolbarbutton-icon { diff --git a/chrome/content/zotero/xpcom/storage.js b/chrome/content/zotero/xpcom/storage.js index c3fd037b6..e74caae33 100644 --- a/chrome/content/zotero/xpcom/storage.js +++ b/chrome/content/zotero/xpcom/storage.js @@ -888,8 +888,7 @@ Zotero.Sync.Storage = new function () { destFile.QueryInterface(Components.interfaces.nsILocalFile); destFile.setRelativeDescriptor(parentDir, fileName); if (destFile.exists()) { - var msg = "ZIP entry '" + fileName + "' " - + " already exists"; + var msg = "ZIP entry '" + fileName + "' " + "already exists"; Zotero.debug(msg, 2); Components.utils.reportError(msg + " in " + funcName); continue; @@ -984,7 +983,22 @@ Zotero.Sync.Storage = new function () { if (file.isFile()) { Zotero.debug("Deleting existing file " + file.leafName); - file.remove(false); + try { + file.remove(false); + } + catch (e) { + if (e.name == 'NS_ERROR_FILE_ACCESS_DENIED') { + Zotero.debug(e); + + // TODO: localize + var msg = "The file '" + file.leafName + "' is in use and cannot " + + "be updated. Please close the file or restart your computer " + + "and try syncing again."; + throw (msg); + } + + throw (e); + } } else if (file.isDirectory()) { Zotero.debug("Deleting existing directory " + file.leafName); diff --git a/chrome/content/zotero/xpcom/storage/zfs.js b/chrome/content/zotero/xpcom/storage/zfs.js index 3ef901319..4a2bc951f 100644 --- a/chrome/content/zotero/xpcom/storage/zfs.js +++ b/chrome/content/zotero/xpcom/storage/zfs.js @@ -190,6 +190,11 @@ Zotero.Sync.Storage.Session.ZFS.prototype.downloadFile = function (request) { else { destFile.append(item.key + '.tmp'); } + + if (destFile.exists()) { + destFile.remove(false); + } + // saveURI() below appears not to create empty files for Content-Length: 0, // so we create one here just in case destFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644); @@ -252,8 +257,7 @@ Zotero.Sync.Storage.Session.ZFS.prototype.downloadFile = function (request) { var wbp = Components .classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"] .createInstance(nsIWBP); - wbp.persistFlags = nsIWBP.PERSIST_FLAGS_BYPASS_CACHE - | nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES; + wbp.persistFlags = nsIWBP.PERSIST_FLAGS_BYPASS_CACHE; wbp.progressListener = listener; wbp.saveURI(uri, null, null, null, null, destFile); } diff --git a/chrome/skin/default/zotero/overlay.css b/chrome/skin/default/zotero/overlay.css index 1c29370a0..58fba9cf5 100644 --- a/chrome/skin/default/zotero/overlay.css +++ b/chrome/skin/default/zotero/overlay.css @@ -221,7 +221,6 @@ #zotero-tb-sync-warning[error=true] { list-style-image: url(chrome://zotero/skin/exclamation.png); - margin-bottom: 2px; } #zotero-tb-sync {