diff --git a/chrome/content/zotero/xpcom/dataDirectory.js b/chrome/content/zotero/xpcom/dataDirectory.js index c060e28d9..c2dcd17de 100644 --- 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 index 8457fb7ac..f1b825ae9 100644 --- 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