Bug 1553929: Make some attempt to correctly match default profiles after profiles.ini has been manually edited by the user. r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D34038

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dave Townsend 2019-06-11 17:32:17 +00:00
Родитель 087af67af1
Коммит 1f96e1db88
3 изменённых файлов: 65 добавлений и 1 удалений

Просмотреть файл

@ -852,6 +852,24 @@ nsresult nsToolkitProfileService::Init() {
currentProfile = new nsToolkitProfile(name, rootDir, localDir, true);
NS_ENSURE_TRUE(currentProfile, NS_ERROR_OUT_OF_MEMORY);
// If a user has modified the ini file path it may make for a valid profile
// path but not match what we would have serialised and so may not match
// the path in the install section. Re-serialise it to get it in the
// expected form again.
bool nowRelative;
nsCString descriptor;
GetProfileDescriptor(currentProfile, descriptor, &nowRelative);
if (isRelative != nowRelative || !descriptor.Equals(filePath)) {
mProfileDB.SetString(profileID.get(), "IsRelative",
nowRelative ? "1" : "0");
mProfileDB.SetString(profileID.get(), "Path", descriptor.get());
// Should we flush now? It costs some startup time and we will fix it on
// the next startup anyway. If something else causes a flush then it will
// be fixed in the ini file then.
}
rv = mProfileDB.GetString(profileID.get(), "Default", buffer);
if (NS_SUCCEEDED(rv) && buffer.EqualsLiteral("1")) {
mNormalDefault = currentProfile;
@ -859,7 +877,7 @@ nsresult nsToolkitProfileService::Init() {
// Is this the default profile for this install?
if (mUseDedicatedProfile && !mDedicatedProfile &&
installProfilePath.Equals(filePath)) {
installProfilePath.Equals(descriptor)) {
// Found a profile for this install.
mDedicatedProfile = currentProfile;
}

Просмотреть файл

@ -0,0 +1,45 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* If a user has modified a relative profile path then there may be issues where
* the profile default setting doesn't match.
*/
add_task(async () => {
let hash = xreDirProvider.getInstallHash();
let profileData = {
options: {
startWithLastProfile: true,
},
profiles: [{
name: "Profile1",
path: "../data/test",
}, {
name: "Profile2",
path: "Path2",
}],
installs: {
[hash]: {
default: "test",
},
},
};
writeProfilesIni(profileData);
let { profile, didCreate } = selectStartupProfile();
checkStartupReason("default");
let service = getProfileService();
Assert.ok(!didCreate, "Should not have created a new profile.");
Assert.equal(profile.name, "Profile1", "Should have selected the expected profile");
Assert.ok(!service.createdAlternateProfile, "Should not have created an alternate profile.");
Assert.equal(profile.name, service.defaultProfile.name, "Should have selected the right default.");
service.flush();
checkProfileService();
});

Просмотреть файл

@ -37,3 +37,4 @@ skip-if = devedition
[test_remove.js]
[test_conflict_profiles.js]
[test_conflict_installs.js]
[test_invalid_descriptor.js]