Skip to content

Commit 13b0d9e

Browse files
committed
Enforce the update channel based on the current client installed.
Signed-off-by: Camila Ayres <[email protected]>
1 parent 8d22b61 commit 13b0d9e

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

src/gui/generalsettings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void GeneralSettings::loadMiscSettings()
283283
#if defined(BUILD_UPDATER)
284284
auto validUpdateChannels = cfgFile.validUpdateChannels();
285285
_ui->updateChannel->addItems(validUpdateChannels);
286-
const auto currentUpdateChannelIndex = validUpdateChannels.indexOf(cfgFile.updateChannel());
286+
const auto currentUpdateChannelIndex = validUpdateChannels.indexOf(cfgFile.currentUpdateChannel());
287287
_ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1? currentUpdateChannelIndex : 0);
288288
connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged);
289289
#endif
@@ -377,7 +377,7 @@ void GeneralSettings::slotUpdateChannelChanged()
377377
};
378378

379379
const auto channel = updateChannelFromLocalized(_ui->updateChannel->currentIndex());
380-
if (channel == ConfigFile().updateChannel()) {
380+
if (channel == ConfigFile().currentUpdateChannel()) {
381381
return;
382382
}
383383

@@ -409,7 +409,7 @@ void GeneralSettings::slotUpdateChannelChanged()
409409
}
410410
#endif
411411
} else {
412-
_ui->updateChannel->setCurrentText(updateChannelToLocalized(ConfigFile().updateChannel()));
412+
_ui->updateChannel->setCurrentText(updateChannelToLocalized(ConfigFile().currentUpdateChannel()));
413413
}
414414
});
415415
msgBox->open();

src/gui/updater/updater.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,15 @@ QUrlQuery Updater::getQueryParams()
9898
query.addQueryItem(QStringLiteral("oem"), Theme::instance()->appName());
9999
query.addQueryItem(QStringLiteral("buildArch"), QSysInfo::buildCpuArchitecture());
100100
query.addQueryItem(QStringLiteral("currentArch"), QSysInfo::currentCpuArchitecture());
101-
102-
const auto suffix = Theme::instance()->versionSuffix();
103-
query.addQueryItem(QStringLiteral("versionsuffix"), suffix);
101+
query.addQueryItem(QStringLiteral("versionsuffix"), Theme::instance()->versionSuffix());
104102

105103
ConfigFile config;
106-
if (const auto channel = config.updateChannel();
107-
channel != QLatin1String("stable")) {
108-
query.addQueryItem(QStringLiteral("channel"), channel);
109-
}
110-
111-
const auto updateSegment = config.updateSegment();
112-
query.addQueryItem(QLatin1String("updatesegment"), QString::number(updateSegment));
104+
query.addQueryItem(QStringLiteral("channel"), config.currentUpdateChannel());
105+
query.addQueryItem(QLatin1String("updatesegment"), QString::number(config.updateSegment()));
113106

114107
return query;
115108
}
116109

117-
118110
QString Updater::getSystemInfo()
119111
{
120112
#ifdef Q_OS_LINUX

src/libsync/configfile.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ static constexpr char forceLoginV2C[] = "forceLoginV2";
109109

110110
static constexpr char certPath[] = "http_certificatePath";
111111
static constexpr char certPasswd[] = "http_certificatePasswd";
112+
113+
static const QStringList validUpdateChannelsList { QStringLiteral("stable"), QStringLiteral("beta"), QStringLiteral("daily") };
114+
static const char stableUpdateChannel[] = "stable";
112115
}
113116

114117
namespace OCC {
@@ -684,25 +687,31 @@ int ConfigFile::updateSegment() const
684687
return segment;
685688
}
686689

687-
QString ConfigFile::updateChannel() const
690+
QStringList ConfigFile::validUpdateChannels() const
688691
{
689-
auto defaultUpdateChannel = Theme::instance()->versionSuffix();
690-
QSettings settings(configFile(), QSettings::IniFormat);
691-
const auto channel = settings.value(QLatin1String(updateChannelC), defaultUpdateChannel).toString();
692-
if (!validUpdateChannels().contains(channel)) {
693-
qCWarning(lcConfigFile()) << "Received invalid update channel from config:"
694-
<< channel
695-
<< "defaulting to:"
696-
<< defaultUpdateChannel;
697-
return defaultUpdateChannel;
692+
return validUpdateChannelsList;
693+
}
694+
695+
QString ConfigFile::defaultUpdateChannel() const
696+
{
697+
if (const auto currentVersionSuffix = Theme::instance()->versionSuffix();validUpdateChannels().contains(currentVersionSuffix)) {
698+
qCWarning(lcConfigFile()) << "Enforcing update channel" << currentVersionSuffix << "because of the version suffix of the current client.";
699+
return currentVersionSuffix;
698700
}
699701

700-
return channel;
702+
return stableUpdateChannel;
701703
}
702704

703-
QStringList ConfigFile::validUpdateChannels() const
705+
QString ConfigFile::currentUpdateChannel() const
704706
{
705-
return { QStringLiteral("stable"), QStringLiteral("beta"), QStringLiteral("daily") };
707+
QSettings settings(configFile(), QSettings::IniFormat);
708+
if (const auto configUpdateChannel = settings.value(QLatin1String(updateChannelC), defaultUpdateChannel()).toString();
709+
validUpdateChannels().contains(configUpdateChannel)) {
710+
qCWarning(lcConfigFile()) << "Config file has a valid update channel:" << configUpdateChannel;
711+
return configUpdateChannel;
712+
}
713+
714+
return defaultUpdateChannel();
706715
}
707716

708717
void ConfigFile::setUpdateChannel(const QString &channel)

src/libsync/configfile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ class OWNCLOUDSYNC_EXPORT ConfigFile
195195
See: https://github.com/nextcloud/client_updater_server/pull/36 */
196196
[[nodiscard]] int updateSegment() const;
197197

198-
[[nodiscard]] QString updateChannel() const;
198+
[[nodiscard]] QString currentUpdateChannel() const;
199+
[[nodiscard]] QString defaultUpdateChannel() const;
199200
[[nodiscard]] QStringList validUpdateChannels() const;
200201
void setUpdateChannel(const QString &channel);
201202

0 commit comments

Comments
 (0)