commit 7f81e62bc893a3032aa07f37db7099497b963264
parent 0b384abe66b5fca38049f5a9b39ef62ef1108b4b
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 1 Apr 2018 13:36:00 -0400
Automatically create new data directories for additional profiles
E.g., if you have a main profile using ~/Zotero and create a second
"Work" profile, a "~/Zotero Work" data directory will be created
automatically and set as a custom data directory
Diffstat:
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/dataDirectory.js b/chrome/content/zotero/xpcom/dataDirectory.js
@@ -182,6 +182,23 @@ Zotero.DataDirectory = {
dataDir = this.defaultDir;
+ // If there's already a profile pointing to the default location, use a different
+ // data directory named after the profile, as long as one either doesn't exist yet or
+ // one does and it contains a database
+ try {
+ if ((yield Zotero.Profile.findOtherProfilesUsingDataDirectory(dataDir, false)).length) {
+ let profileName = OS.Path.basename(Zotero.Profile.dir).match(/[^.]+\.(.+)/)[1];
+ let newDataDir = this.defaultDir + ' ' + profileName;
+ if (!(yield OS.File.exists(newDataDir))
+ || (yield OS.File.exists(OS.Path.join(newDataDir, dbFilename)))) {
+ dataDir = newDataDir;
+ }
+ }
+ }
+ catch (e) {
+ Zotero.logError(e);
+ }
+
// Check for ~/Zotero/zotero.sqlite
let dbFile = OS.Path.join(dataDir, dbFilename);
if (yield OS.File.exists(dbFile)) {
diff --git a/chrome/content/zotero/xpcom/profile.js b/chrome/content/zotero/xpcom/profile.js
@@ -129,10 +129,12 @@ Zotero.Profile = {
/**
* Find other profile directories (for this app or the other app) using the given data directory
*
+ * @param {String} dataDir
+ * @param {Boolean} [includeOtherApps=false] - Check Firefox profiles
* @return {String[]}
*/
- findOtherProfilesUsingDataDirectory: Zotero.Promise.coroutine(function* (dataDir) {
- let otherAppProfiles = yield this._findOtherAppProfiles();
+ findOtherProfilesUsingDataDirectory: Zotero.Promise.coroutine(function* (dataDir, includeOtherApps = true) {
+ let otherAppProfiles = includeOtherApps ? (yield this._findOtherAppProfiles()) : [];
let otherProfiles = (yield this._findOtherProfiles()).concat(otherAppProfiles);
// First get profiles pointing at this directory