commit e8a2667bdcf48f5d6dfeed21500bda4c8bd6a305
parent ffcccf0867788adb5400d4511f5a050ff5acdd98
Author: Kui-Feng Lee <thinker.li@gmail.com>
Date: Mon, 29 Dec 2025 21:08:19 +0000
Bug 2003137 - Check profiles.ini of legacy dir. r=gerard-majax
Check the existence of legacy dir not only against the directory but
also "profiles.ini" in it.
Prevent Firefox from ignoring XDG profiles when legacy directory is
accidentally created. Even when using XDG base directory for profiles,
Firefox can sometimes accidentally create the legacy profile directory
(~/.mozilla/firefox) (e.g., via mozregression or crash reports). When
this happens, Firefox mistakenly defaults to using the legacy
directory, ignoring valid XDG profiles, even if the legacy directory
is empty. This change checks for the existence of "profiles.ini"
within the legacy directory. If the file is missing, the legacy
directory is considered empty and is skipped, ensuring the application
correctly uses profiles from the XDG directory.
Differential Revision: https://phabricator.services.mozilla.com/D275906
Diffstat:
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp
@@ -1363,7 +1363,19 @@ bool nsXREDirProvider::LegacyHomeExists(nsIFile** aFile) {
rv = AppendFromAppData(localDir, true);
NS_ENSURE_SUCCESS(rv, false);
- rv = localDir->Exists(&exists);
+ // Check for profiles.ini instead of directory existence
+ nsCOMPtr<nsIFile> profilesIni;
+ rv = localDir->Clone(getter_AddRefs(profilesIni));
+ NS_ENSURE_SUCCESS(rv, false);
+
+ /* Fix bug 2003137. "profiles.ini" is only created when profiles exist.
+ * Other subsystems (crash reporting, telemetry) may create subdirectories
+ * without this file.
+ */
+ rv = profilesIni->AppendNative("profiles.ini"_ns);
+ NS_ENSURE_SUCCESS(rv, false);
+
+ rv = profilesIni->Exists(&exists);
NS_ENSURE_SUCCESS(rv, false);
// Give a chance to (3)
@@ -1378,6 +1390,10 @@ bool nsXREDirProvider::LegacyHomeExists(nsIFile** aFile) {
rv = userDir->AppendRelativeNativePath(mozUserDir);
NS_ENSURE_SUCCESS(rv, false);
+ // Check for profiles.ini in MOZ_USER_DIR
+ rv = userDir->AppendNative("profiles.ini"_ns);
+ NS_ENSURE_SUCCESS(rv, false);
+
rv = userDir->Exists(&exists);
NS_ENSURE_SUCCESS(rv, false);
}