Skip to content

Commit 530dbf1

Browse files
author
Stephen A Pohl
committed
Bug 1854868: Remove the use of update-settings.ini on macOS and query the accepted MAR channels from the macOS Framework instead. r=bytesized
Differential Revision: https://phabricator.services.mozilla.com/D189488
1 parent 26ab0df commit 530dbf1

File tree

6 files changed

+102
-46
lines changed

6 files changed

+102
-46
lines changed

browser/installer/package-manifest.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@
145145
#endif
146146
@RESPATH@/application.ini
147147
#ifdef MOZ_UPDATER
148+
# update-settings.ini has been removed on macOS.
149+
#ifndef XP_MACOSX
148150
@RESPATH@/update-settings.ini
149151
#endif
152+
#endif
150153
@RESPATH@/platform.ini
151154
#ifndef MOZ_FOLD_LIBS
152155
@BINPATH@/@DLL_PREFIX@mozsqlite3@DLL_SUFFIX@

browser/installer/removed-files.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@
7878
@DIR_RESOURCES@defaults/pref/channel-prefs.js
7979
@DIR_RESOURCES@defaults/pref/
8080
#endif
81+
82+
# update-settings.ini has been removed on macOS.
83+
#ifdef XP_MACOSX
84+
@DIR_RESOURCES@update-settings.ini
85+
#endif

build/moz.build

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ if CONFIG["MOZ_APP_BASENAME"]:
107107
)
108108

109109
FINAL_TARGET_FILES += ["!application.ini"]
110-
if CONFIG["MOZ_WIDGET_TOOLKIT"] != "android" and CONFIG["MOZ_UPDATER"]:
110+
if (
111+
CONFIG["MOZ_WIDGET_TOOLKIT"] not in ("android", "cocoa")
112+
and CONFIG["MOZ_UPDATER"]
113+
):
111114
FINAL_TARGET_PP_FILES += ["update-settings.ini"]
112115

113116
GeneratedFile(

toolkit/mozapps/update/common/readstrings.cpp

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ class AutoFILE {
3838
FILE* fp_;
3939
};
4040

41-
class AutoCharArray {
42-
public:
43-
explicit AutoCharArray(size_t len) { ptr_ = new char[len]; }
44-
~AutoCharArray() { delete[] ptr_; }
45-
operator char*() { return ptr_; }
46-
47-
private:
48-
char* ptr_;
49-
};
50-
5141
static const char kNL[] = "\r\n";
5242
static const char kEquals[] = "=";
5343
static const char kWhitespace[] = " \t";
@@ -153,7 +143,8 @@ int ReadStrings(const NS_tchar* path, const char* keyList,
153143
}
154144

155145
size_t flen = size_t(len);
156-
AutoCharArray fileContents(flen + 1);
146+
147+
char* fileContents = new char[flen + 1];
157148
if (!fileContents) {
158149
return READ_STRINGS_MEM_ERROR;
159150
}
@@ -170,12 +161,53 @@ int ReadStrings(const NS_tchar* path, const char* keyList,
170161

171162
fileContents[flen] = '\0';
172163

173-
char* buffer = fileContents;
164+
int result = ReadStringsFromBuffer(fileContents, keyList, numStrings, results,
165+
section);
166+
delete[] fileContents;
167+
return result;
168+
}
169+
170+
// A wrapper function to read strings for the updater.
171+
// Added for compatibility with the original code.
172+
int ReadStrings(const NS_tchar* path, StringTable* results) {
173+
const unsigned int kNumStrings = 2;
174+
const char* kUpdaterKeys = "Title\0Info\0";
175+
mozilla::UniquePtr<char[]> updater_strings[kNumStrings];
176+
177+
int result = ReadStrings(path, kUpdaterKeys, kNumStrings, updater_strings);
178+
179+
if (result == OK) {
180+
results->title.swap(updater_strings[0]);
181+
results->info.swap(updater_strings[1]);
182+
}
183+
184+
return result;
185+
}
186+
187+
/**
188+
* A very basic parser for updater.ini taken mostly from nsINIParser.cpp
189+
* that can be used by standalone apps.
190+
*
191+
* @param stringBuffer The string buffer to parse
192+
* @param keyList List of zero-delimited keys ending with two zero
193+
* characters
194+
* @param numStrings Number of strings to read into results buffer - must be
195+
* equal to the number of keys
196+
* @param results Array of strings. Array's length must be equal to
197+
* numStrings. Each string will be populated with the value
198+
* corresponding to the key with the same index in keyList.
199+
* @param section Optional name of the section to read; defaults to
200+
* "Strings"
201+
*/
202+
int ReadStringsFromBuffer(char* stringBuffer, const char* keyList,
203+
unsigned int numStrings,
204+
mozilla::UniquePtr<char[]>* results,
205+
const char* section) {
174206
bool inStringsSection = false;
175207

176208
unsigned int read = 0;
177209

178-
while (char* token = NS_strtok(kNL, &buffer)) {
210+
while (char* token = NS_strtok(kNL, &stringBuffer)) {
179211
if (token[0] == '#' || token[0] == ';') { // it's a comment
180212
continue;
181213
}
@@ -233,23 +265,6 @@ int ReadStrings(const NS_tchar* path, const char* keyList,
233265
return (read == numStrings) ? OK : PARSE_ERROR;
234266
}
235267

236-
// A wrapper function to read strings for the updater.
237-
// Added for compatibility with the original code.
238-
int ReadStrings(const NS_tchar* path, StringTable* results) {
239-
const unsigned int kNumStrings = 2;
240-
const char* kUpdaterKeys = "Title\0Info\0";
241-
mozilla::UniquePtr<char[]> updater_strings[kNumStrings];
242-
243-
int result = ReadStrings(path, kUpdaterKeys, kNumStrings, updater_strings);
244-
245-
if (result == OK) {
246-
results->title.swap(updater_strings[0]);
247-
results->info.swap(updater_strings[1]);
248-
}
249-
250-
return result;
251-
}
252-
253268
IniReader::IniReader(const NS_tchar* iniPath,
254269
const char* section /* = nullptr */) {
255270
if (iniPath) {

toolkit/mozapps/update/common/readstrings.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ int ReadStrings(const NS_tchar* path, const char* keyList,
3737
unsigned int numStrings, mozilla::UniquePtr<char[]>* results,
3838
const char* section = nullptr);
3939

40+
/**
41+
* This function reads in localized strings corresponding to the keys from a
42+
* given string buffer.
43+
*/
44+
int ReadStringsFromBuffer(char* stringBuffer, const char* keyList,
45+
unsigned int numStrings,
46+
mozilla::UniquePtr<char[]>* results,
47+
const char* section = nullptr);
48+
4049
/**
4150
* This class is meant to be a slightly cleaner interface into the ReadStrings
4251
* function.

toolkit/mozapps/update/updater/updater.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
#include "updatecommon.h"
4848
#ifdef XP_MACOSX
49+
# include "UpdateSettingsUtil.h"
4950
# include "updaterfileutils_osx.h"
5051
#endif // XP_MACOSX
5152

@@ -2659,23 +2660,38 @@ static void WaitForServiceFinishThread(void* param) {
26592660
#endif
26602661

26612662
#ifdef MOZ_VERIFY_MAR_SIGNATURE
2663+
# ifndef XP_MACOSX
26622664
/**
26632665
* This function reads in the ACCEPTED_MAR_CHANNEL_IDS from update-settings.ini
26642666
*
2665-
* @param path The path to the ini file that is to be read
2666-
* @param results A pointer to the location to store the read strings
2667+
* @param aPath The path to the ini file that is to be read
2668+
* @param aResults A pointer to the location to store the read strings
26672669
* @return OK on success
26682670
*/
2669-
static int ReadMARChannelIDs(const NS_tchar* path,
2670-
MARChannelStringTable* results) {
2671+
static int ReadMARChannelIDsFromPath(const NS_tchar* aPath,
2672+
MARChannelStringTable* aResults) {
26712673
const unsigned int kNumStrings = 1;
26722674
const char* kUpdaterKeys = "ACCEPTED_MAR_CHANNEL_IDS\0";
2673-
int result = ReadStrings(path, kUpdaterKeys, kNumStrings,
2674-
&results->MARChannelID, "Settings");
2675-
2676-
return result;
2675+
return ReadStrings(aPath, kUpdaterKeys, kNumStrings, &aResults->MARChannelID,
2676+
"Settings");
26772677
}
2678-
#endif
2678+
# else // XP_MACOSX
2679+
/**
2680+
* This function reads in the ACCEPTED_MAR_CHANNEL_IDS from a string buffer.
2681+
*
2682+
* @param aChannels A string buffer containing the MAR channel(s).
2683+
* @param aResults A pointer to the location to store the read strings.
2684+
* @return OK on success
2685+
*/
2686+
static int ReadMARChannelIDsFromBuffer(char* aChannels,
2687+
MARChannelStringTable* aResults) {
2688+
const unsigned int kNumStrings = 1;
2689+
const char* kUpdaterKeys = "ACCEPTED_MAR_CHANNEL_IDS\0";
2690+
return ReadStringsFromBuffer(aChannels, kUpdaterKeys, kNumStrings,
2691+
&aResults->MARChannelID, "Settings");
2692+
}
2693+
# endif // XP_MACOSX
2694+
#endif // MOZ_VERIFY_MAR_SIGNATURE
26792695

26802696
static int GetUpdateFileName(NS_tchar* fileName, int maxChars) {
26812697
NS_tsnprintf(fileName, maxChars, NS_T("%s/update.mar"), gPatchDirPath);
@@ -2700,17 +2716,22 @@ static void UpdateThreadFunc(void* param) {
27002716
}
27012717

27022718
if (rv == OK) {
2719+
MARChannelStringTable MARStrings;
2720+
# ifndef XP_MACOSX
27032721
NS_tchar updateSettingsPath[MAXPATHLEN];
27042722
NS_tsnprintf(updateSettingsPath,
27052723
sizeof(updateSettingsPath) / sizeof(updateSettingsPath[0]),
2706-
# ifdef XP_MACOSX
2707-
NS_T("%s/Contents/Resources/update-settings.ini"),
2724+
NS_T("%s/update-settings.ini"), gInstallDirPath);
2725+
rv = ReadMARChannelIDsFromPath(updateSettingsPath, &MARStrings);
27082726
# else
2709-
NS_T("%s/update-settings.ini"),
2727+
if (auto marChannels =
2728+
UpdateSettingsUtil::GetAcceptedMARChannelsValue()) {
2729+
rv = ReadMARChannelIDsFromBuffer(marChannels->data(), &MARStrings);
2730+
} else {
2731+
rv = UPDATE_SETTINGS_FILE_CHANNEL;
2732+
}
27102733
# endif
2711-
gInstallDirPath);
2712-
MARChannelStringTable MARStrings;
2713-
if (ReadMARChannelIDs(updateSettingsPath, &MARStrings) != OK) {
2734+
if (rv != OK) {
27142735
rv = UPDATE_SETTINGS_FILE_CHANNEL;
27152736
} else {
27162737
rv = gArchiveReader.VerifyProductInformation(

0 commit comments

Comments
 (0)