Show better error message if data dir can't be created

This commit is contained in:
Dan Stillman 2017-09-12 02:35:06 -04:00
parent e669bf03b0
commit a47c332895
3 changed files with 77 additions and 1 deletions

View file

@ -338,7 +338,75 @@ Zotero.DataDirectory = {
}
Zotero.debug("Using data directory " + dataDir);
yield Zotero.File.createDirectoryIfMissingAsync(dataDir);
try {
yield Zotero.File.createDirectoryIfMissingAsync(dataDir);
}
catch (e) {
if (e instanceof OS.File.Error
&& (('unixErrno' in e && e.unixErrno == OS.Constants.libc.EACCES)
|| ('winLastError' in e && e.winLastError == OS.Constants.Win.ERROR_ACCESS_DENIED))) {
Zotero.restarting = true;
let isDefaultDir = dataDir == Zotero.DataDirectory.defaultDir;
let ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.createInstance(Components.interfaces.nsIPromptService);
let buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING
+ ps.BUTTON_POS_1 * ps.BUTTON_TITLE_IS_STRING;
if (!isDefaultDir) {
buttonFlags += ps.BUTTON_POS_2 * ps.BUTTON_TITLE_IS_STRING;
}
let title = Zotero.getString('general.accessDenied');
let msg = Zotero.getString('dataDir.dirCannotBeCreated', [Zotero.appName, dataDir])
+ "\n\n"
+ Zotero.getString('dataDir.checkDirWriteAccess', Zotero.appName);
let index;
if (isDefaultDir) {
index = ps.confirmEx(null,
title,
msg,
buttonFlags,
Zotero.getString('dataDir.chooseNewDataDirectory'),
Zotero.getString('general.quit'),
null, null, {}
);
if (index == 0) {
let changed = yield Zotero.DataDirectory.choose(true);
if (!changed) {
Zotero.Utilities.Internal.quit();
}
}
else if (index == 1) {
Zotero.Utilities.Internal.quit();
}
}
else {
index = ps.confirmEx(null,
title,
msg,
buttonFlags,
Zotero.getString('dataDir.useDefaultLocation'),
Zotero.getString('general.quit'),
Zotero.getString('dataDir.chooseNewDataDirectory'),
null, {}
);
if (index == 0) {
Zotero.DataDirectory.set(Zotero.DataDirectory.defaultDir);
Zotero.Utilities.Internal.quit(true);
}
else if (index == 1) {
Zotero.Utilities.Internal.quit();
}
else if (index == 2) {
let changed = yield Zotero.DataDirectory.choose(true);
if (!changed) {
Zotero.Utilities.Internal.quit();
return;
}
}
}
return;
}
}
this._cache(dataDir);
}),

View file

@ -29,6 +29,9 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/osfile.jsm");
Components.utils.import("resource://gre/modules/PluralForm.jsm");
Components.classes["@mozilla.org/net/osfileconstantsservice;1"]
.getService(Components.interfaces.nsIOSFileConstantsService)
.init();
Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
@ -288,6 +291,9 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
try {
yield Zotero.DataDirectory.init();
if (this.restarting) {
return;
}
var dataDir = Zotero.DataDirectory.dir;
}
catch (e) {

View file

@ -119,6 +119,8 @@ attachmentBasePath.clearBasePath.existingAttachments.singular = One existing at
attachmentBasePath.clearBasePath.existingAttachments.plural = %S existing attachments within the old base directory will be converted to use absolute paths.
attachmentBasePath.clearBasePath.button = Clear Base Directory Setting
dataDir.dirCannotBeCreated = The %S data directory (%S) cannot be created.
dataDir.checkDirWriteAccess = Make sure you have write access to this directory and that security software isnt preventing %S from writing to the disk.
dataDir.databaseCannotBeOpened = The %S database cannot be opened.
dataDir.checkPermissions = Make sure you have read and write permissions for all files in the %1$S data directory and that security software isnt preventing %1$S from accessing that directory.
dataDir.moveToDefaultLocation = You may be able to fix this problem by moving the data directory to the new default location in your home directory. %S will automatically detect the new location.