www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit e9439c978b493eb3b7b8cb78e52288f17c86646f
parent d8d9758f27f9b0b081b9302512b11cfc817c9197
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 11 Sep 2017 03:49:06 -0400

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

Diffstat:
Mchrome/content/zotero/preferences/preferences_advanced.js | 6++++++
Mchrome/content/zotero/preferences/preferences_advanced.xul | 5+++++
Mchrome/content/zotero/xpcom/dataDirectory.js | 36+++++++++++++++++++++++++++++++++++-
Mchrome/content/zotero/xpcom/zotero.js | 24++++++++++++++----------
Mchrome/locale/en-US/zotero/preferences.dtd | 1+
Mchrome/skin/default/zotero/preferences.css | 14++++++++++++++
Mcomponents/zotero-service.js | 2++
7 files changed, 77 insertions(+), 11 deletions(-)

diff --git a/chrome/content/zotero/preferences/preferences_advanced.js b/chrome/content/zotero/preferences/preferences_advanced.js @@ -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( diff --git a/chrome/content/zotero/preferences/preferences_advanced.xul b/chrome/content/zotero/preferences/preferences_advanced.xul @@ -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()"/> diff --git a/chrome/content/zotero/xpcom/dataDirectory.js b/chrome/content/zotero/xpcom/dataDirectory.js @@ -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; diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -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. diff --git a/chrome/locale/en-US/zotero/preferences.dtd b/chrome/locale/en-US/zotero/preferences.dtd @@ -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…"> diff --git a/chrome/skin/default/zotero/preferences.css b/chrome/skin/default/zotero/preferences.css @@ -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; +} diff --git a/components/zotero-service.js b/components/zotero-service.js @@ -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;