Enforce the update channel based on the current client installed.
authorCamila Ayres <hello@camilasan.com>
Wed, 26 Jun 2024 19:14:07 +0000 (21:14 +0200)
committerCamila Ayres <hello@camilasan.com>
Wed, 3 Jul 2024 14:32:10 +0000 (16:32 +0200)
Signed-off-by: Camila Ayres <hello@camilasan.com>
src/gui/generalsettings.cpp
src/gui/updater/updater.cpp
src/libsync/configfile.cpp
src/libsync/configfile.h

index 1851b7cc2a9be3bb66090e1ca0c30bcadd394a54..562913ae4261af2fd0f8c0caa9491359ea36d04b 100644 (file)
@@ -283,7 +283,7 @@ void GeneralSettings::loadMiscSettings()
 #if defined(BUILD_UPDATER)
     auto validUpdateChannels = cfgFile.validUpdateChannels();
     _ui->updateChannel->addItems(validUpdateChannels);
-    const auto currentUpdateChannelIndex = validUpdateChannels.indexOf(cfgFile.updateChannel());
+    const auto currentUpdateChannelIndex = validUpdateChannels.indexOf(cfgFile.currentUpdateChannel());
     _ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1? currentUpdateChannelIndex : 0);
     connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged);
 #endif
@@ -377,7 +377,7 @@ void GeneralSettings::slotUpdateChannelChanged()
     };
 
     const auto channel = updateChannelFromLocalized(_ui->updateChannel->currentIndex());
-    if (channel == ConfigFile().updateChannel()) {
+    if (channel == ConfigFile().currentUpdateChannel()) {
         return;
     }
 
@@ -409,7 +409,7 @@ void GeneralSettings::slotUpdateChannelChanged()
             }
 #endif
         } else {
-            _ui->updateChannel->setCurrentText(updateChannelToLocalized(ConfigFile().updateChannel()));
+            _ui->updateChannel->setCurrentText(updateChannelToLocalized(ConfigFile().currentUpdateChannel()));
         }
     });
     msgBox->open();
index 2e49e8706af088db37fe4fdd9f67eccba55d9fd2..87957c724e3d73d8eac0a71cb588c4b518143cd1 100644 (file)
@@ -98,23 +98,15 @@ QUrlQuery Updater::getQueryParams()
     query.addQueryItem(QStringLiteral("oem"), Theme::instance()->appName());
     query.addQueryItem(QStringLiteral("buildArch"), QSysInfo::buildCpuArchitecture());
     query.addQueryItem(QStringLiteral("currentArch"), QSysInfo::currentCpuArchitecture());
-
-    const auto suffix = Theme::instance()->versionSuffix();
-    query.addQueryItem(QStringLiteral("versionsuffix"), suffix);
+    query.addQueryItem(QStringLiteral("versionsuffix"), Theme::instance()->versionSuffix());
 
     ConfigFile config;
-    if (const auto channel = config.updateChannel();
-        channel != QLatin1String("stable")) {
-        query.addQueryItem(QStringLiteral("channel"), channel);
-    }
-
-    const auto updateSegment = config.updateSegment();
-    query.addQueryItem(QLatin1String("updatesegment"), QString::number(updateSegment));
+    query.addQueryItem(QStringLiteral("channel"), config.currentUpdateChannel());
+    query.addQueryItem(QLatin1String("updatesegment"), QString::number(config.updateSegment()));
 
     return query;
 }
 
-
 QString Updater::getSystemInfo()
 {
 #ifdef Q_OS_LINUX
index b43317ae938e9ff964c8971138eee2b0649ecb4a..0a803595f2248799248cb7ce28b40b39c04f5a6a 100644 (file)
@@ -109,6 +109,9 @@ static constexpr char forceLoginV2C[] = "forceLoginV2";
 
 static constexpr char certPath[] = "http_certificatePath";
 static constexpr char certPasswd[] = "http_certificatePasswd";
+
+static const QStringList validUpdateChannelsList { QStringLiteral("stable"), QStringLiteral("beta"), QStringLiteral("daily") };
+static const char stableUpdateChannel[] = "stable";
 }
 
 namespace OCC {
@@ -684,25 +687,31 @@ int ConfigFile::updateSegment() const
     return segment;
 }
 
-QString ConfigFile::updateChannel() const
+QStringList ConfigFile::validUpdateChannels() const
 {
-    auto defaultUpdateChannel = Theme::instance()->versionSuffix();
-    QSettings settings(configFile(), QSettings::IniFormat);
-    const auto channel = settings.value(QLatin1String(updateChannelC), defaultUpdateChannel).toString();
-    if (!validUpdateChannels().contains(channel)) {
-        qCWarning(lcConfigFile()) << "Received invalid update channel from config:"
-                                  << channel
-                                  << "defaulting to:"
-                                  << defaultUpdateChannel;
-        return defaultUpdateChannel;
+    return validUpdateChannelsList;
+}
+
+QString ConfigFile::defaultUpdateChannel() const
+{
+    if (const auto currentVersionSuffix = Theme::instance()->versionSuffix();validUpdateChannels().contains(currentVersionSuffix)) {
+        qCWarning(lcConfigFile()) << "Enforcing update channel" << currentVersionSuffix << "because of the version suffix of the current client.";
+        return currentVersionSuffix;
     }
 
-    return channel;
+    return stableUpdateChannel;
 }
 
-QStringList ConfigFile::validUpdateChannels() const
+QString ConfigFile::currentUpdateChannel() const
 {
-    return { QStringLiteral("stable"), QStringLiteral("beta"), QStringLiteral("daily") };
+    QSettings settings(configFile(), QSettings::IniFormat);
+    if (const auto configUpdateChannel = settings.value(QLatin1String(updateChannelC), defaultUpdateChannel()).toString();
+        validUpdateChannels().contains(configUpdateChannel)) {
+        qCWarning(lcConfigFile()) << "Config file has a valid update channel:" << configUpdateChannel;
+        return configUpdateChannel;
+    }
+
+    return defaultUpdateChannel();
 }
 
 void ConfigFile::setUpdateChannel(const QString &channel)
index 851f89d10bb555476eba5b8e42e8aafcd78cc883..6b10a8f2fd1fed572a9879e336330b072b612575 100644 (file)
@@ -195,7 +195,8 @@ public:
         See: https://github.com/nextcloud/client_updater_server/pull/36 */
     [[nodiscard]] int updateSegment() const;
 
-    [[nodiscard]] QString updateChannel() const;
+    [[nodiscard]] QString currentUpdateChannel() const;
+    [[nodiscard]] QString defaultUpdateChannel() const;
     [[nodiscard]] QStringList validUpdateChannels() const;
     void setUpdateChannel(const QString &channel);