Allow setting data directory via -datadir command-line flag

Can be an absolute path or 'profile' to use 'zotero' subdirectory of
profile directory as in earlier versions (but which won't be treated as
a legacy location eligible for migration)

Closes #1305
This commit is contained in:
Dan Stillman 2017-09-11 03:49:06 -04:00
parent d8d9758f27
commit e9439c978b
7 changed files with 77 additions and 11 deletions

View file

@ -298,6 +298,12 @@ Zotero_Preferences.Advanced = {
var currentDir = Zotero.DataDirectory.dir;
var defaultDataDir = Zotero.DataDirectory.defaultDir;
if (Zotero.forceDataDir) {
document.getElementById('command-line-data-dir-path').textContent = currentDir;
document.getElementById('command-line-data-dir').hidden = false;
document.getElementById('data-dir').hidden = true;
}
// Change "Use profile directory" label to home directory location unless using profile dir
if (useDataDir || currentDir == defaultDataDir) {
document.getElementById('default-data-dir').setAttribute(

View file

@ -184,6 +184,11 @@
</hbox>
</radiogroup>
<vbox id="command-line-data-dir" hidden="true">
<description id="command-line-data-dir-path"/>
<label value="&zotero.preferences.dataDir.viaCommandLine;"/>
</vbox>
<hbox>
<button label="&zotero.preferences.dataDir.reveal;"
oncommand="Zotero.DataDirectory.reveal()"/>

View file

@ -54,7 +54,37 @@ Zotero.DataDirectory = {
init: Zotero.Promise.coroutine(function* () {
var dataDir;
var dbFilename = this.getDatabaseFilename();
if (Zotero.Prefs.get('useDataDir')) {
// Handle directory specified on command line
if (Zotero.forceDataDir) {
let dir = Zotero.forceDataDir;
// Profile subdirectory
if (dir == 'profile') {
dataDir = OS.Path.join(Zotero.Profile.dir, this.legacyDirName);
}
// Absolute path
else {
// Ignore non-absolute paths
if ("winIsAbsolute" in OS.Path) {
if (!OS.Path.winIsAbsolute(dir)) {
dir = false;
}
}
else if (!dir.startsWith('/')) {
dir = false;
}
if (!dir) {
throw `-datadir requires an absolute path or 'profile' ('${Zotero.forceDataDir}' given)`;
}
// Require parent directory to exist
if (!(yield OS.File.exists(OS.Path.dirname(dir)))) {
throw `Parent directory of -datadir ${dir} not found`;
}
dataDir = dir;
}
}
else if (Zotero.Prefs.get('useDataDir')) {
let prefVal = Zotero.Prefs.get('dataDir');
// Convert old persistent descriptor pref to string path and clear obsolete lastDataDir pref
//
@ -660,6 +690,10 @@ Zotero.DataDirectory = {
return false;
}
if (Zotero.forceDataDir) {
return false;
}
// Legacy default or set to legacy default from other program (Standalone/Z4Fx) to share data
if (!Zotero.Prefs.get('useDataDir') || this.isLegacy(currentDir)) {
return true;

View file

@ -180,6 +180,8 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
'skipBundledFiles'
];
opts.filter(opt => options[opt]).forEach(opt => this[opt] = true);
this.forceDataDir = options.forceDataDir;
}
this.mainThread = Services.tm.mainThread;
@ -378,16 +380,18 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
}
if (!Zotero.isConnector) {
yield Zotero.DataDirectory.checkForLostLegacy();
if (this.restarting) {
return;
}
yield Zotero.DataDirectory.checkForMigration(
dataDir, Zotero.DataDirectory.defaultDir
);
if (this.skipLoading) {
return;
if (!this.forceDataDir) {
yield Zotero.DataDirectory.checkForLostLegacy();
if (this.restarting) {
return;
}
yield Zotero.DataDirectory.checkForMigration(
dataDir, Zotero.DataDirectory.defaultDir
);
if (this.skipLoading) {
return;
}
}
// Make sure data directory isn't in Dropbox, etc.

View file

@ -193,6 +193,7 @@
<!ENTITY zotero.preferences.dataDir.useProfile "Use profile directory">
<!ENTITY zotero.preferences.dataDir.custom "Custom:">
<!ENTITY zotero.preferences.dataDir.choose "Choose…">
<!ENTITY zotero.preferences.dataDir.viaCommandLine "(specified via command line)">
<!ENTITY zotero.preferences.dataDir.reveal "Show Data Directory">
<!ENTITY zotero.preferences.dataDir.migrate "Migrate To New Default Location…">

View file

@ -289,3 +289,17 @@ treechildren::-moz-tree-checkbox(checked){
in your extension or elsewhere. */
list-style-image: url("chrome://global/skin/checkbox/cbox-check.gif");
}
/* Advanced pane */
#command-line-data-dir description {
font-size: 12px;
cursor: text;
-moz-user-select: text;
}
#command-line-data-dir label {
font-size: 11px;
font-style: italic;
padding-top: .4em;
padding-bottom: .4em;
}

View file

@ -503,6 +503,8 @@ ZoteroCommandLineHandler.prototype = {
zInitOptions.forceDebugLog = 1;
}
zInitOptions.forceDataDir = cmdLine.handleFlagWithParam("datadir", false);
// handler to open Zotero pane at startup in Zotero for Firefox
if (!isStandalone() && cmdLine.handleFlag("ZoteroPaneOpen", false)) {
zInitOptions.openPane = true;