commit 2edaea48293198953792192e1999b36d2d031271
parent 4506d592993c309bb1c707dbd53e493c6c570bfb
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 13 Apr 2011 15:56:11 +0000
- Use a single, better error for all file access errors during syncing
- Recommend checking WebDAV settings on WebDAV error
Diffstat:
5 files changed, 108 insertions(+), 137 deletions(-)
diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js
@@ -323,4 +323,92 @@ Zotero.File = new function(){
browser.addEventListener("pageshow", onpageshow, false);
}
+
+
+ // TODO: localize
+ this.checkFileAccessError = function (e, file, operation) {
+ if (file) {
+ var str = "The file '" + file.path + "' ";
+ }
+ else {
+ var str = "A file ";
+ }
+
+ switch (operation) {
+ case 'create':
+ var opWord = "created";
+ break;
+
+ case 'update':
+ var opWord = "updated";
+ break;
+
+ case 'delete':
+ var opWord = "deleted";
+ break;
+
+ default:
+ var opWord = "updated";
+ }
+
+ if (e.name == 'NS_ERROR_FILE_ACCESS_DENIED'
+ // Shows up on some Windows systems
+ || e.name == 'NS_ERROR_FAILURE') {
+ Zotero.debug(e);
+ // TODO: localize
+ str = str + "cannot be " + opWord + ".";
+ var checkFileWindows = "Check that the file is not currently "
+ + "in use and that it is not marked as read-only. To check "
+ + "all files in your Zotero data directory, right-click on "
+ + "the 'zotero' directory, click Properties, and ensure that "
+ + "the Read-Only checkbox is empty.";
+ var checkFileOther = "Check that the file is not currently "
+ + "in use and that its permissions allow write access.";
+ var msg = str + " "
+ + (!Zotero.isWin ? checkFileWindows : checkFileOther)
+ + "\n\n"
+ + "Restarting your computer or disabling security "
+ + "software may also help.";
+
+ if (operation == 'create') {
+ var e = new Zotero.Error(
+ msg,
+ 0,
+ {
+ dialogButtonText: "Show Parent Directory",
+ dialogButtonCallback: function () {
+ try {
+ file.parent.QueryInterface(Components.interfaces.nsILocalFile).reveal();
+ }
+ // Unsupported on some platforms
+ catch (e2) {
+ Zotero.debug(e2);
+ }
+ }
+ }
+ );
+ }
+ else {
+ var e = new Zotero.Error(
+ msg,
+ 0,
+ {
+ dialogButtonText: "Show File",
+ dialogButtonCallback: function () {
+ try {
+ file.QueryInterface(Components.interfaces.nsILocalFile);
+ file.reveal();
+ }
+ // Unsupported on some platforms
+ catch (e2) {
+ Zotero.debug(e2);
+ }
+ }
+ }
+ );
+ }
+ }
+
+ throw (e);
+ }
}
diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js
@@ -954,11 +954,15 @@ Zotero.Fulltext = new function(){
case 'application/pdf':
var cacheFile = this.getItemCacheFile(itemID);
if (cacheFile.exists()) {
- cacheFile.remove(false);
+ try {
+ cacheFile.remove(false);
+ }
+ catch (e) {
+ Zotero.File.checkFileAccessError(e, cacheFile, 'delete');
+ }
}
break;
}
-
}
diff --git a/chrome/content/zotero/xpcom/storage.js b/chrome/content/zotero/xpcom/storage.js
@@ -542,38 +542,7 @@ Zotero.Sync.Storage = new function () {
file.lastModifiedTime = attachmentData[item.id].mtime;
}
catch (e) {
- if (e.name == 'NS_ERROR_FILE_ACCESS_DENIED'
- // Shows up on some Windows systems
- || e.name == 'NS_ERROR_FAILURE') {
- Zotero.debug(e);
- // TODO: localize
- var fileCannotBeUpdated = "The file '" + file.path
- + "' cannot be updated.";
- var checkFileWindows = "Check that the file is not currently "
- + "in use and that it is not marked read-only.";
- var checkFileOther = "Check that the file is not currently "
- + "in use and that its permissions allow write access.";
- var msg = fileCannotBeUpdated + " "
- + (Zotero.isWin ? checkFileWindows : checkFileOther) + "\n\n"
- + "Restarting your computer or disabling security "
- + "software may also help.";
- var e = new Zotero.Error(
- msg,
- 0,
- {
- dialogButtonText: "Show File",
- dialogButtonCallback: function () {
- try {
- file.reveal();
- }
- // Unsupported on some platforms
- catch (e) {}
- }
- }
- );
- }
-
- throw (e);
+ Zotero.File.checkFileAccessError(e, file, 'update');
}
continue;
}
@@ -743,38 +712,7 @@ Zotero.Sync.Storage = new function () {
}
}
catch (e) {
- if (e.name == 'NS_ERROR_FILE_ACCESS_DENIED'
- // Shows up on some Windows systems
- || e.name == 'NS_ERROR_FAILURE') {
- Zotero.debug(e);
- // TODO: localize
- var fileCannotBeUpdated = "The file '" + file.path
- + "' cannot be updated.";
- var checkFileWindows = "Check that the file is not currently "
- + "in use and that it is not marked read-only.";
- var checkFileOther = "Check that the file is not currently "
- + "in use and that its permissions allow write access.";
- var msg = fileCannotBeUpdated + " "
- + (Zotero.isWin ? checkFileWindows : checkFileOther) + "\n\n"
- + "Restarting your computer or disabling security "
- + "software may also help.";
- var e = new Zotero.Error(
- msg,
- 0,
- {
- dialogButtonText: "Show File",
- dialogButtonCallback: function () {
- try {
- file.reveal();
- }
- // Unsupported on some platforms
- catch (e) {}
- }
- }
- );
- }
-
- throw (e);
+ Zotero.File.checkFileAccessError(e, file, 'update');
}
Zotero.Sync.Storage.setSyncedModificationTime(item.id, syncModTime, updateItem);
@@ -1061,33 +999,7 @@ Zotero.Sync.Storage = new function () {
zipFile.remove(false);
}
catch (e) {
- if (e.name == 'NS_ERROR_FAILURE') {
- Zotero.debug(e);
- // TODO: localize
- var msg = "Zotero could not delete the temporary sync file '"
- + zipFile.path + "'. Delete the file manually and try syncing again."
- + "\n\n"
- + "If you receive this message repeatedly, restarting your "
- + "computer or disabling security software may help.";
- var e = new Zotero.Error(
- msg,
- 0,
- {
- dialogButtonText: "Show File",
- dialogButtonCallback: function () {
- try {
- zipFile.reveal();
- }
- // Unsupported on some platforms
- catch (e3) {}
- }
- }
- );
-
- throw (e);
- }
-
- throw (e);
+ Zotero.File.checkFileAccessError(e, zipFile, 'delete');
}
// TODO: Remove prop file to trigger reuploading, in case it was an upload error?
@@ -1275,17 +1187,7 @@ Zotero.Sync.Storage = new function () {
zipReader.extract(entryName, destFile);
}
catch (e) {
- if (e.name == 'NS_ERROR_FILE_ACCESS_DENIED') {
- Zotero.debug(e);
- // TODO: localize
- var msg = "Zotero was unable to create a file during syncing."
- + "\n\n"
- + "Restarting your computer or disabling anti-virus/security "
- + "software may fix the problem.";
- throw (msg);
- }
-
- throw (e);
+ Zotero.File.checkFileAccessError(e, destFile, 'create');
}
var origPath = destFile.path;
@@ -1358,27 +1260,7 @@ Zotero.Sync.Storage = new function () {
file.remove(false);
}
catch (e) {
- if (e.name == 'NS_ERROR_FILE_ACCESS_DENIED'
- // Shows up on some Windows systems
- || e.name == 'NS_ERROR_FAILURE') {
- Zotero.debug(e);
- // TODO: localize
- var fileCannotBeUpdated = "The file '" + file.leafName
- + "' cannot be updated.";
- var checkFileWindows = "Check that the file is not currently "
- + "in use and that it is not marked read-only.";
- var checkFileOther = "Check that the file is not currently "
- + "in use and that its permissions allow write access.";
- var msg = Zotero.localeJoin([
- fileCannotBeUpdated,
- Zotero.isWin ? checkFileWindows : checkFileOther
- ]) + "\n\n"
- + "Restarting your computer or disabling security "
- + "software may also help.";
- throw (msg);
- }
-
- throw (e);
+ Zotero.File.checkFileAccessError(e, file, 'delete');
}
}
else if (file.isDirectory()) {
diff --git a/chrome/content/zotero/xpcom/storage/webdav.js b/chrome/content/zotero/xpcom/storage/webdav.js
@@ -48,8 +48,8 @@ Zotero.Sync.Storage.Session.WebDAV.prototype.includeGroupItems = false;
// TEMP
// TODO: localize
-Zotero.Sync.Storage.Session.WebDAV.prototype.defaultError = "A WebDAV file sync error occurred. Please try syncing again.\n\nIf you receive this message repeatedly, submit an error report and post the Report ID to a new thread in the Zotero Forums.";
-Zotero.Sync.Storage.Session.WebDAV.prototype.defaultErrorRestart = "A WebDAV file sync error occurred. Please restart Firefox and try syncing again.\n\nIf you receive this message repeatedly, submit an error report and post the Report ID to a new thread in the Zotero Forums.";
+Zotero.Sync.Storage.Session.WebDAV.prototype.defaultError = "A WebDAV file sync error occurred. Please try syncing again.\n\nIf you receive this message repeatedly, check your WebDAV server settings in the Sync pane of the Zotero preferences.";
+Zotero.Sync.Storage.Session.WebDAV.prototype.defaultErrorRestart = "A WebDAV file sync error occurred. Please restart Firefox and try syncing again.\n\nIf you receive this message repeatedly, check your WebDAV server settings in the Sync pane of the Zotero preferences.";
Zotero.Sync.Storage.Session.WebDAV.prototype.__defineGetter__('enabled', function () {
diff --git a/chrome/content/zotero/xpcom/storage/zfs.js b/chrome/content/zotero/xpcom/storage/zfs.js
@@ -241,21 +241,18 @@ Zotero.Sync.Storage.Session.ZFS.prototype.downloadFile = function (request) {
destFile.remove(false);
}
catch (e) {
- // TODO: localize
- var msg = "Zotero was unable to delete a temporary file in "
- + destFile.parent.path + " during syncing."
- + "\n\n"
- + "Restarting your computer or disabling anti-virus/security "
- + "software may fix the problem.";
- Zotero.debug(e, 1);
- Components.utils.reportError(e);
- self.onError(msg);
+ Zotero.File.checkFileAccessError(e, destFile, 'delete');
}
}
// 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);
+ try {
+ destFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644);
+ }
+ catch (e) {
+ Zotero.File.checkFileAccessError(e, destFile, 'create');
+ }
var listener = new Zotero.Sync.Storage.StreamListener(
{