Fix checking for Firefox profiles high up in filesystem

This was triggering an erroneous warning dialog about a failure to check
for Firefox profiles during Linux tests (where the profile is at
something like /tmp/tmp.l5phnqSxBH/Zotero), but it could also affect a
custom profile directory location.
This commit is contained in:
Dan Stillman 2023-05-25 03:33:49 -04:00
parent feb12fafe8
commit 6e2ec2300d
2 changed files with 31 additions and 18 deletions

View file

@ -239,19 +239,21 @@ Zotero.DataDirectory = {
// Check Firefox directory
//
if (!dataDirNamedAfterProfile) {
let profilesParent = OS.Path.dirname(Zotero.Profile.getOtherAppProfilesDir());
Zotero.debug("Looking for Firefox profile in " + profilesParent);
// get default profile
// Get default profile in Firefox dir
let defProfile;
try {
defProfile = yield Zotero.Profile.getDefaultInProfilesDir(profilesParent);
}
catch (e) {
Zotero.debug("An error occurred locating the Firefox profile; "
+ "not attempting to migrate from Zotero for Firefox");
Zotero.logError(e);
Zotero.fxProfileAccessError = true;
let profilesDir = Zotero.Profile.getOtherAppProfilesDir();
let profilesParent = profilesDir ? OS.Path.dirname(profilesDir) : null;
if (profilesParent) {
Zotero.debug("Looking for Firefox profile in " + profilesParent);
try {
defProfile = yield Zotero.Profile.getDefaultInProfilesDir(profilesParent);
}
catch (e) {
Zotero.debug("An error occurred locating the Firefox profile; "
+ "not attempting to migrate from Zotero for Firefox");
Zotero.logError(e);
Zotero.fxProfileAccessError = true;
}
}
if (defProfile) {
let profileDir = defProfile[0];
@ -721,7 +723,11 @@ Zotero.DataDirectory = {
if (currentDir != this.defaultDir) return;
if (Zotero.Prefs.get('ignoreLegacyDataDir.auto') || Zotero.Prefs.get('ignoreLegacyDataDir.explicit')) return;
try {
let profilesParent = OS.Path.dirname(Zotero.Profile.getOtherAppProfilesDir());
let profilesDir = Zotero.Profile.getOtherAppProfilesDir();
let profilesParent = profilesDir ? OS.Path.dirname(profilesDir) : null;
if (!profilesParent) {
return;
}
Zotero.debug("Looking for Firefox profile in " + profilesParent);
// get default profile

View file

@ -95,10 +95,13 @@ Zotero.Profile = {
* Get the path to the Profiles directory of the other app from this one (Firefox or Zotero),
* which may or may not exist
*
* @return {String} - Path
* @return {String|null} - Path, or null if none due to filesystem location
*/
getOtherAppProfilesDir: function () {
var dir = OS.Path.dirname(OS.Path.dirname(OS.Path.dirname(this.dir)));
if (dir === '' || dir == '.') {
return null;
}
if (Zotero.isStandalone) {
if (Zotero.isWin) {
@ -205,7 +208,11 @@ Zotero.Profile = {
*/
checkFirefoxProfileAccess: async function () {
try {
let profilesParent = OS.Path.dirname(Zotero.Profile.getOtherAppProfilesDir());
let profilesDir = Zotero.Profile.getOtherAppProfilesDir();
if (!profilesDir) {
return true;
}
let profilesParent = OS.Path.dirname(profilesDir);
Zotero.debug("Looking for Firefox profile in " + profilesParent);
let defProfile = await this.getDefaultInProfilesDir(profilesParent);
if (defProfile) {
@ -314,8 +321,8 @@ Zotero.Profile = {
*
* @return {String[]} - Array of paths
*/
_findOtherAppProfiles: Zotero.Promise.coroutine(function* () {
_findOtherAppProfiles: async function () {
var dir = this.getOtherAppProfilesDir();
return (yield OS.File.exists(dir)) ? this._getProfilesInDir(dir) : [];
})
return dir && await OS.File.exists(dir) ? this._getProfilesInDir(dir) : [];
}
};