Bug 1872482 - recreate non-ephemeral background task profile directory if it's missing r=mossop

Differential Revision: https://phabricator.services.mozilla.com/D210677
This commit is contained in:
Eric Chen 2024-05-24 14:34:49 +00:00
parent 031a90d97c
commit ddda7b8c9c
2 changed files with 33 additions and 5 deletions

View File

@ -1539,6 +1539,8 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
nsAutoCString buffer;
rv = mProfileDB.GetString("BackgroundTasksProfiles", profilePrefix.get(),
buffer);
bool exists = false;
if (NS_SUCCEEDED(rv)) {
// We have a record of one! Use it.
rv = rootDir->Clone(getter_AddRefs(file));
@ -1546,7 +1548,17 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
rv = file->AppendNative(buffer);
NS_ENSURE_SUCCESS(rv, rv);
} else {
rv = file->Exists(&exists);
NS_ENSURE_SUCCESS(rv, rv);
if (!exists) {
printf_stderr(
"Profile directory does not exist, create a new directory");
}
}
if (!exists) {
nsCString saltedProfilePrefix = profilePrefix;
SaltProfileName(saltedProfilePrefix);

View File

@ -17,10 +17,11 @@ add_task(condition, async () => {
let hash = xreDirProvider.getInstallHash();
let saltedPath = `saltSALT.${vendor}BackgroundTask-${hash}-not_ephemeral_profile`;
let profileName = `${vendor}BackgroundTask-${hash}-not_ephemeral_profile`;
// See note about ordering below.
BACKGROUNDTASKS_PROFILE_DATA.backgroundTasksProfiles.splice(0, 0, {
name: `${vendor}BackgroundTask-${hash}-not_ephemeral_profile`,
name: profileName,
path: saltedPath,
});
@ -38,19 +39,34 @@ add_task(condition, async () => {
bts.overrideBackgroundTaskNameForTesting("not_ephemeral_profile");
let { didCreate, rootDir } = selectStartupProfile();
checkStartupReason("backgroundtask-not-ephemeral");
Assert.equal(didCreate, false, "Re-used existing non-ephemeral profile");
//test directory will be created
Assert.equal(
didCreate,
true,
"Re-used existing non-ephemeral profile, but should create a new directory for it"
);
Assert.equal(
rootDir.exists(),
true,
"rootDir has a directory in the file system"
);
let profileData = readProfilesIni();
// Profile names are lexicographically ordered, and `not_ephemeral_profile`
// sorts before `unrelated_task`.
Assert.equal(profileData.backgroundTasksProfiles.length, 2);
Assert.deepEqual(profileData, BACKGROUNDTASKS_PROFILE_DATA);
//make sure the new salted path is recorded in profiles.ini
let createdProfile = profileData.backgroundTasksProfiles.find(
searchProfile => searchProfile.name == profileName
);
Assert.ok(
rootDir.path.endsWith(saltedPath),
rootDir.path.endsWith(createdProfile.path),
`rootDir "${rootDir.path}" ends with salted path "${saltedPath}"`
);