Convert dataDir pref to string path and remove lastDataDir
.persistentDescriptor now appears to return (and parse) a string path anyway on macOS, which is the only place where it didn't use a string path to begin with, so this will only affect earlier users.
This commit is contained in:
parent
f2163b3433
commit
a5b222edac
|
@ -225,20 +225,9 @@ Zotero_Preferences.Advanced = {
|
||||||
|
|
||||||
|
|
||||||
getDataDirPath: function () {
|
getDataDirPath: function () {
|
||||||
var desc = Zotero.Prefs.get('dataDir');
|
// TEMP: lastDataDir can be removed once old persistent descriptors have been
|
||||||
if (desc == '') {
|
// converted, which they are in getZoteroDirectory() in 5.0
|
||||||
return '';
|
return Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir') || '';
|
||||||
}
|
|
||||||
|
|
||||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
|
||||||
createInstance(Components.interfaces.nsILocalFile);
|
|
||||||
try {
|
|
||||||
file.persistentDescriptor = desc;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return file.path;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -282,11 +282,13 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_OK)
|
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_OK)
|
||||||
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
|
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
|
||||||
+ (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING);
|
+ (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING);
|
||||||
|
// TEMP: lastDataDir can be removed once old persistent descriptors have been
|
||||||
|
// converted, which they are in getZoteroDirectory() in 5.0
|
||||||
|
var previousDir = Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir');
|
||||||
var index = ps.confirmEx(null,
|
var index = ps.confirmEx(null,
|
||||||
Zotero.getString('general.error'),
|
Zotero.getString('general.error'),
|
||||||
Zotero.startupError + '\n\n' +
|
Zotero.startupError + '\n\n' +
|
||||||
Zotero.getString('dataDir.previousDir') + ' '
|
Zotero.getString('dataDir.previousDir') + ' ' + previousDir,
|
||||||
+ Zotero.Prefs.get('lastDataDir'),
|
|
||||||
buttonFlags, null,
|
buttonFlags, null,
|
||||||
Zotero.getString('dataDir.useProfileDir', Zotero.appName),
|
Zotero.getString('dataDir.useProfileDir', Zotero.appName),
|
||||||
Zotero.getString('general.locate'),
|
Zotero.getString('general.locate'),
|
||||||
|
@ -922,17 +924,39 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
if (Zotero.Prefs.get('useDataDir')) {
|
if (Zotero.Prefs.get('useDataDir')) {
|
||||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
var file = Components.classes["@mozilla.org/file/local;1"].
|
||||||
createInstance(Components.interfaces.nsILocalFile);
|
createInstance(Components.interfaces.nsILocalFile);
|
||||||
try {
|
let prefVal = Zotero.Prefs.get('dataDir');
|
||||||
file.persistentDescriptor = Zotero.Prefs.get('dataDir');
|
// Convert old persistent descriptor pref to string path and clear obsolete lastDataDir pref
|
||||||
|
//
|
||||||
|
// persistentDescriptor now appears to return (and parse) a string path anyway on macOS,
|
||||||
|
// which is the only place where it didn't use a string path to begin with, but be explicit
|
||||||
|
// just in case there's some difference.
|
||||||
|
//
|
||||||
|
// A post-Mozilla prefs migration should do this same check, and then this conditional can
|
||||||
|
// be removed.
|
||||||
|
if (Zotero.Prefs.get('lastDataDir')) {
|
||||||
|
try {
|
||||||
|
file.persistentDescriptor = prefVal;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.debug("Persistent descriptor in extensions.zotero.dataDir did not resolve", 1);
|
||||||
|
e = { name: "NS_ERROR_FILE_NOT_FOUND" };
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
|
this.setDataDirectory(file.path);
|
||||||
|
if (!file.exists()) {
|
||||||
|
var e = { name: "NS_ERROR_FILE_NOT_FOUND" };
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
else {
|
||||||
Zotero.debug("Persistent descriptor in extensions.zotero.dataDir did not resolve", 1);
|
try {
|
||||||
e = { name: "NS_ERROR_FILE_NOT_FOUND" };
|
file = Zotero.File.pathToFile(prefVal);
|
||||||
throw (e);
|
}
|
||||||
}
|
catch (e) {
|
||||||
if (!file.exists()) {
|
Zotero.debug(`Invalid path '${prefVal}' in dataDir pref`, 1);
|
||||||
var e = { name: "NS_ERROR_FILE_NOT_FOUND" };
|
e = { name: "NS_ERROR_FILE_NOT_FOUND" };
|
||||||
throw (e);
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1286,9 +1310,9 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
|
|
||||||
|
|
||||||
this.setDataDirectory = function (path) {
|
this.setDataDirectory = function (path) {
|
||||||
let dir = Zotero.File.pathToFile(path);
|
Zotero.Prefs.set('dataDir', path);
|
||||||
Zotero.Prefs.set('dataDir', dir.persistentDescriptor);
|
// Clear legacy pref
|
||||||
Zotero.Prefs.set('lastDataDir', dir.path);
|
Zotero.Prefs.clear('lastDataDir');
|
||||||
Zotero.Prefs.set('useDataDir', true);
|
Zotero.Prefs.set('useDataDir', true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ pref("extensions.zotero.saveRelativeAttachmentPath", false);
|
||||||
pref("extensions.zotero.baseAttachmentPath", '');
|
pref("extensions.zotero.baseAttachmentPath", '');
|
||||||
pref("extensions.zotero.useDataDir", false);
|
pref("extensions.zotero.useDataDir", false);
|
||||||
pref("extensions.zotero.dataDir", '');
|
pref("extensions.zotero.dataDir", '');
|
||||||
pref("extensions.zotero.lastDataDir", '');
|
|
||||||
pref("extensions.zotero.warnOnUnsafeDataDir", true);
|
pref("extensions.zotero.warnOnUnsafeDataDir", true);
|
||||||
pref("extensions.zotero.debug.log",false);
|
pref("extensions.zotero.debug.log",false);
|
||||||
pref("extensions.zotero.debug.stackTrace", false);
|
pref("extensions.zotero.debug.stackTrace", false);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user