From 39f85219b90855f673de9cec2c46a5d4a3bca614 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 7 Nov 2022 18:33:39 +0100 Subject: [PATCH 1/9] fix migration from old settings configuration files Signed-off-by: Matthieu Gallien --- src/gui/accountmanager.cpp | 82 ++++++++++++++---------- src/gui/folderman.cpp | 124 +++++++++++++++++++++++-------------- 2 files changed, 128 insertions(+), 78 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 9d8c93914..58b786088 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -49,7 +49,7 @@ constexpr auto httpAuthPrefix = "http_"; constexpr auto webflowAuthPrefix = "webflow_"; constexpr auto legacyRelativeConfigLocationC = "/ownCloud/owncloud.cfg"; -constexpr auto legacyOcSettingsC = "ownCloud"; +constexpr auto legacyCfgFileNameC = "owncloud.cfg"; // The maximum versions that this client can read constexpr auto maxAccountsVersion = 2; @@ -142,43 +142,55 @@ bool AccountManager::restoreFromLegacySettings() qCInfo(lcAccountManager) << "Migrate: restoreFromLegacySettings, checking settings group" << Theme::instance()->appName(); - // try to open the correctly themed settings + // try to open the correctly themed settings auto settings = ConfigFile::settingsWithGroup(Theme::instance()->appName()); - // if the settings file could not be opened, the childKeys list is empty - // then try to load settings from a very old place + // if the settings file could not be opened, the childKeys list is empty + // then try to load settings from a very old place if (settings->childKeys().isEmpty()) { // Now try to open the original ownCloud settings to see if they exist. - auto oCCfgFile = QDir::fromNativeSeparators(settings->fileName()); + const auto fullLegacyCfgFile = QDir::fromNativeSeparators(settings->fileName()); // replace the last two segments with ownCloud/owncloud.cfg - oCCfgFile = oCCfgFile.left(oCCfgFile.lastIndexOf('/')); - oCCfgFile = oCCfgFile.left(oCCfgFile.lastIndexOf('/')); - oCCfgFile += QLatin1String(legacyRelativeConfigLocationC); + const auto legacyCfgFileParentFolder = fullLegacyCfgFile.left(fullLegacyCfgFile.lastIndexOf('/')); + const auto legacyCfgFileGrandParentFolder = legacyCfgFileParentFolder.left(legacyCfgFileParentFolder.lastIndexOf('/')); - qCInfo(lcAccountManager) << "Migrate: checking old config " << oCCfgFile; + for (const auto &configFile : {QString{legacyCfgFileParentFolder + "/" + legacyCfgFileNameC}, QString{legacyCfgFileGrandParentFolder + QLatin1String(legacyRelativeConfigLocationC)}}) { + if (QFileInfo::exists(configFile)) { + qCInfo(lcAccountManager) << "Migrate: checking old config " << configFile; - QFileInfo fi(oCCfgFile); - if (fi.isReadable()) { - std::unique_ptr oCSettings(new QSettings(oCCfgFile, QSettings::IniFormat)); - oCSettings->beginGroup(QLatin1String(legacyOcSettingsC)); + QFileInfo fi(configFile); + if (fi.isReadable()) { + std::unique_ptr oCSettings(new QSettings(configFile, QSettings::IniFormat)); + if (oCSettings->status() != QSettings::Status::NoError) { + qCInfo(lcAccountManager) << "Error reading legacy configuration file" << oCSettings->status(); + } - // Check the theme url to see if it is the same url that the oC config was for - auto overrideUrl = Theme::instance()->overrideServerUrl(); - if (!overrideUrl.isEmpty()) { - if (overrideUrl.endsWith('/')) { - overrideUrl.chop(1); - } - auto oCUrl = oCSettings->value(QLatin1String(urlC)).toString(); - if (oCUrl.endsWith('/')) { - oCUrl.chop(1); - } + // Check the theme url to see if it is the same url that the oC config was for + auto overrideUrl = Theme::instance()->overrideServerUrl(); + qCInfo(lcAccountManager) << "Migrate: overrideUrl" << overrideUrl; + if (!overrideUrl.isEmpty()) { + if (overrideUrl.endsWith('/')) { + overrideUrl.chop(1); + } + auto oCUrl = oCSettings->value(QLatin1String(urlC)).toString(); + if (oCUrl.endsWith('/')) { + oCUrl.chop(1); + } - // in case the urls are equal reset the settings object to read from - // the ownCloud settings object - qCInfo(lcAccountManager) << "Migrate oC config if " << oCUrl << " == " << overrideUrl << ":" - << (oCUrl == overrideUrl ? "Yes" : "No"); - if (oCUrl == overrideUrl) { - settings = std::move(oCSettings); + // in case the urls are equal reset the settings object to read from + // the ownCloud settings object + qCInfo(lcAccountManager) << "Migrate oC config if " << oCUrl << " == " << overrideUrl << ":" + << (oCUrl == overrideUrl ? "Yes" : "No"); + if (oCUrl == overrideUrl) { + qCInfo(lcAccountManager) << "Copy settings" << oCSettings->allKeys().join(", "); + settings = std::move(oCSettings); + } + } else { + qCInfo(lcAccountManager) << "Copy settings" << oCSettings->allKeys().join(", "); + settings = std::move(oCSettings); + } + + break; } } } @@ -186,9 +198,15 @@ bool AccountManager::restoreFromLegacySettings() // Try to load the single account. if (!settings->childKeys().isEmpty()) { - if (const auto acc = loadAccountHelper(*settings)) { - addAccount(acc); - return true; + settings->beginGroup(accountsC); + const auto childGroups = settings->childGroups(); + for (const auto &accountId : childGroups) { + settings->beginGroup(accountId); + if (const auto acc = loadAccountHelper(*settings)) { + addAccount(acc); + + return true; + } } } return false; diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index a5a13a51d..42cdcdfa2 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -39,12 +39,11 @@ #include namespace { -#ifndef VERSION_C -#define VERSION_C -constexpr auto versionC= "version"; -#endif +constexpr auto accountsC = "Accounts"; +constexpr auto foldersC = "Folders"; +constexpr auto versionC = "version"; +constexpr auto maxFoldersVersion = 1; } -static const int maxFoldersVersion = 1; namespace OCC { @@ -347,7 +346,7 @@ int FolderMan::setupFoldersMigration() { ConfigFile cfg; QDir storageDir(cfg.configPath()); - _folderConfigPath = cfg.configPath() + QLatin1String("folders"); + _folderConfigPath = cfg.configPath(); qCInfo(lcFolderMan) << "Setup folders from " << _folderConfigPath << "(migration)"; @@ -509,28 +508,9 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat // Check if the filename is equal to the group setting. If not, use the group // name as an alias. QStringList groups = settings.childGroups(); - - if (!groups.contains(escapedAlias) && groups.count() > 0) { - escapedAlias = groups.first(); - } - - settings.beginGroup(escapedAlias); // read the group with the same name as the file which is the folder alias - - QString path = settings.value(QLatin1String("localPath")).toString(); - QString backend = settings.value(QLatin1String("backend")).toString(); - QString targetPath = settings.value(QLatin1String("targetPath")).toString(); - bool paused = settings.value(QLatin1String("paused"), false).toBool(); - // QString connection = settings.value( QLatin1String("connection") ).toString(); - QString alias = unescapeAlias(escapedAlias); - - if (backend.isEmpty() || backend != QLatin1String("owncloud")) { - qCWarning(lcFolderMan) << "obsolete configuration of type" << backend; - return nullptr; - } - - // cut off the leading slash, oCUrl always has a trailing. - if (targetPath.startsWith(QLatin1Char('/'))) { - targetPath.remove(0, 1); + if (groups.isEmpty()) { + qCWarning(lcFolderMan) << "empty file:" << cfgFile.filePath(); + return folder; } if (!accountState) { @@ -538,28 +518,80 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat return nullptr; } - FolderDefinition folderDefinition; - folderDefinition.alias = alias; - folderDefinition.localPath = path; - folderDefinition.targetPath = targetPath; - folderDefinition.paused = paused; - folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles(); + settings.beginGroup(accountsC); + const auto rootChildGroups = settings.childGroups(); + for (const auto &accountId : rootChildGroups) { + qCDebug(lcFolderMan) << "try to migrate accountId:" << accountId; + settings.beginGroup(accountId); + settings.beginGroup(foldersC); - folder = addFolderInternal(folderDefinition, accountState, std::make_unique()); - if (folder) { - QStringList blackList = settings.value(QLatin1String("blackList")).toStringList(); - if (!blackList.empty()) { - //migrate settings - folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList); - settings.remove(QLatin1String("blackList")); - // FIXME: If you remove this codepath, you need to provide another way to do - // this via theme.h or the normal FolderMan::setupFolders + if (settings.childGroups().isEmpty()) { + continue; } - folder->saveToSettings(); + const auto childGroups = settings.childGroups(); + for (const auto &alias : childGroups) { + settings.beginGroup(alias); + qCDebug(lcFolderMan) << "try to migrate folder alias:" << alias; + + const auto path = settings.value(QLatin1String("localPath")).toString(); + const auto targetPath = settings.value(QLatin1String("targetPath")).toString(); + const auto journalPath = settings.value(QLatin1String("journalPath")).toString(); + const auto paused = settings.value(QLatin1String("paused"), false).toBool(); + const auto ignoreHiddenFiles = settings.value(QLatin1String("ignoreHiddenFiles"), false).toBool(); + + if (path.isEmpty()) { + qCDebug(lcFolderMan) << "localPath is empty"; + settings.endGroup(); + continue; + } + + if (targetPath.isEmpty()) { + qCDebug(lcFolderMan) << "targetPath is empty"; + settings.endGroup(); + continue; + } + + if (journalPath.isEmpty()) { + qCDebug(lcFolderMan) << "journalPath is empty"; + settings.endGroup(); + continue; + } + + FolderDefinition folderDefinition; + folderDefinition.alias = alias; + folderDefinition.localPath = path; + folderDefinition.targetPath = targetPath; + folderDefinition.journalPath = journalPath; + folderDefinition.paused = paused; + folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles; + + folder = addFolderInternal(folderDefinition, accountState, std::make_unique()); + if (folder) { + const auto blackList = settings.value(QLatin1String("blackList")).toStringList(); + if (!blackList.empty()) { + //migrate settings + folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList); + settings.remove(QLatin1String("blackList")); + // FIXME: If you remove this codepath, you need to provide another way to do + // this via theme.h or the normal FolderMan::setupFolders + } + + folder->saveToSettings(); + } + qCInfo(lcFolderMan) << "Migrated!" << folder; + settings.sync(); + + if (folder) { + return folder; + } + + settings.endGroup(); + } + + settings.endGroup(); + settings.endGroup(); } - qCInfo(lcFolderMan) << "Migrated!" << folder; - settings.sync(); return folder; } From 98be5fdd18afaa0aeba11cf1c8c7fff4b24fd491 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 1 Dec 2022 14:04:02 +0100 Subject: [PATCH 2/9] Add full list of possible legacy config locations Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 58b786088..c8f71dbaa 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "clientsideencryption.h" namespace { @@ -142,19 +143,34 @@ bool AccountManager::restoreFromLegacySettings() qCInfo(lcAccountManager) << "Migrate: restoreFromLegacySettings, checking settings group" << Theme::instance()->appName(); - // try to open the correctly themed settings + // try to open the correctly themed settings auto settings = ConfigFile::settingsWithGroup(Theme::instance()->appName()); - // if the settings file could not be opened, the childKeys list is empty - // then try to load settings from a very old place + // if the settings file could not be opened, the childKeys list is empty + // then try to load settings from a very old place if (settings->childKeys().isEmpty()) { - // Now try to open the original ownCloud settings to see if they exist. + // Legacy settings used QDesktopServices to get the location for the config folder in 2.4 and before + const auto legacy2_4CfgSettingsLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const auto legacy2_4CfgFileParentFolder = legacy2_4CfgSettingsLocation.left(legacy2_4CfgSettingsLocation.lastIndexOf('/')); + + // 2.5+ (rest of 2.x series) + const auto legacy2_5CfgSettingsLocation = QStandardPaths::writableLocation(Utility::isWindows() ? QStandardPaths::AppDataLocation : QStandardPaths::AppConfigLocation); + const auto legacy2_5CfgFileParentFolder = legacy2_5CfgSettingsLocation.left(legacy2_5CfgSettingsLocation.lastIndexOf('/')); + + // Now try the locations we use today const auto fullLegacyCfgFile = QDir::fromNativeSeparators(settings->fileName()); - // replace the last two segments with ownCloud/owncloud.cfg const auto legacyCfgFileParentFolder = fullLegacyCfgFile.left(fullLegacyCfgFile.lastIndexOf('/')); const auto legacyCfgFileGrandParentFolder = legacyCfgFileParentFolder.left(legacyCfgFileParentFolder.lastIndexOf('/')); - for (const auto &configFile : {QString{legacyCfgFileParentFolder + "/" + legacyCfgFileNameC}, QString{legacyCfgFileGrandParentFolder + QLatin1String(legacyRelativeConfigLocationC)}}) { + const auto legacyCfgFileNamePath = QString(QStringLiteral("/") + legacyCfgFileNameC); + const auto legacyCfgFileRelativePath = QString(legacyRelativeConfigLocationC); + + const auto legacyLocations = QVector{legacy2_4CfgFileParentFolder + legacyCfgFileRelativePath, + legacy2_5CfgFileParentFolder + legacyCfgFileRelativePath, + legacyCfgFileParentFolder + legacyCfgFileNamePath, + legacyCfgFileGrandParentFolder + legacyCfgFileRelativePath}; + + for (const auto &configFile : legacyLocations) { if (QFileInfo::exists(configFile)) { qCInfo(lcAccountManager) << "Migrate: checking old config " << configFile; From 5548a4181b62c9affe8816e6104c8e4d09d63d70 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 6 Dec 2022 14:07:28 +0100 Subject: [PATCH 3/9] Replace QDesktopServices datalocation with emulated version of it Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index c8f71dbaa..9ca69858e 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -150,7 +150,7 @@ bool AccountManager::restoreFromLegacySettings() // then try to load settings from a very old place if (settings->childKeys().isEmpty()) { // Legacy settings used QDesktopServices to get the location for the config folder in 2.4 and before - const auto legacy2_4CfgSettingsLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const auto legacy2_4CfgSettingsLocation = QString(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/data")); const auto legacy2_4CfgFileParentFolder = legacy2_4CfgSettingsLocation.left(legacy2_4CfgSettingsLocation.lastIndexOf('/')); // 2.5+ (rest of 2.x series) From 0f9ddcddcb4359be9ed34487e8c30b4c223d2595 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 7 Dec 2022 17:11:28 +0100 Subject: [PATCH 4/9] Fix includes in accountmanager.cpp Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 9ca69858e..2a96a3a60 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -13,20 +13,21 @@ */ #include "accountmanager.h" -#include "configfile.h" + #include "sslerrordialog.h" #include "proxyauthhandler.h" #include "common/asserts.h" -#include -#include -#include -#include +#include "creds/credentialsfactory.h" +#include "creds/abstractcredentials.h" +#include "libsync/clientsideencryption.h" +#include "libsync/configfile.h" +#include "libsync/cookiejar.h" +#include "libsync/theme.h" + #include #include #include #include -#include -#include "clientsideencryption.h" namespace { constexpr auto urlC = "url"; From d8e8a43cff26f7bfc03850cd04dd41fd26f3907e Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 15 Dec 2022 13:24:34 +0100 Subject: [PATCH 5/9] Constify config file QFileInfo, create directly in if statement Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 2a96a3a60..95ba39b63 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -172,11 +172,12 @@ bool AccountManager::restoreFromLegacySettings() legacyCfgFileGrandParentFolder + legacyCfgFileRelativePath}; for (const auto &configFile : legacyLocations) { - if (QFileInfo::exists(configFile)) { + if (const QFileInfo configFileInfo(configFile); + configFileInfo.exists()) { + qCInfo(lcAccountManager) << "Migrate: checking old config " << configFile; - QFileInfo fi(configFile); - if (fi.isReadable()) { + if (configFileInfo.isReadable()) { std::unique_ptr oCSettings(new QSettings(configFile, QSettings::IniFormat)); if (oCSettings->status() != QSettings::Status::NoError) { qCInfo(lcAccountManager) << "Error reading legacy configuration file" << oCSettings->status(); From f4bca991e1f5113c97967ffd7187c9a81df3f3ce Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 15 Dec 2022 13:27:12 +0100 Subject: [PATCH 6/9] Make checks for config file more concise, warn when file not readable Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 56 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 95ba39b63..32cb3abc3 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -173,43 +173,43 @@ bool AccountManager::restoreFromLegacySettings() for (const auto &configFile : legacyLocations) { if (const QFileInfo configFileInfo(configFile); - configFileInfo.exists()) { + configFileInfo.exists() && configFileInfo.isReadable()) { qCInfo(lcAccountManager) << "Migrate: checking old config " << configFile; - if (configFileInfo.isReadable()) { - std::unique_ptr oCSettings(new QSettings(configFile, QSettings::IniFormat)); - if (oCSettings->status() != QSettings::Status::NoError) { - qCInfo(lcAccountManager) << "Error reading legacy configuration file" << oCSettings->status(); + std::unique_ptr oCSettings(new QSettings(configFile, QSettings::IniFormat)); + if (oCSettings->status() != QSettings::Status::NoError) { + qCInfo(lcAccountManager) << "Error reading legacy configuration file" << oCSettings->status(); + } + + // Check the theme url to see if it is the same url that the oC config was for + auto overrideUrl = Theme::instance()->overrideServerUrl(); + qCInfo(lcAccountManager) << "Migrate: overrideUrl" << overrideUrl; + if (!overrideUrl.isEmpty()) { + if (overrideUrl.endsWith('/')) { + overrideUrl.chop(1); + } + auto oCUrl = oCSettings->value(QLatin1String(urlC)).toString(); + if (oCUrl.endsWith('/')) { + oCUrl.chop(1); } - // Check the theme url to see if it is the same url that the oC config was for - auto overrideUrl = Theme::instance()->overrideServerUrl(); - qCInfo(lcAccountManager) << "Migrate: overrideUrl" << overrideUrl; - if (!overrideUrl.isEmpty()) { - if (overrideUrl.endsWith('/')) { - overrideUrl.chop(1); - } - auto oCUrl = oCSettings->value(QLatin1String(urlC)).toString(); - if (oCUrl.endsWith('/')) { - oCUrl.chop(1); - } - - // in case the urls are equal reset the settings object to read from - // the ownCloud settings object - qCInfo(lcAccountManager) << "Migrate oC config if " << oCUrl << " == " << overrideUrl << ":" - << (oCUrl == overrideUrl ? "Yes" : "No"); - if (oCUrl == overrideUrl) { - qCInfo(lcAccountManager) << "Copy settings" << oCSettings->allKeys().join(", "); - settings = std::move(oCSettings); - } - } else { + // in case the urls are equal reset the settings object to read from + // the ownCloud settings object + qCInfo(lcAccountManager) << "Migrate oC config if " << oCUrl << " == " << overrideUrl << ":" + << (oCUrl == overrideUrl ? "Yes" : "No"); + if (oCUrl == overrideUrl) { qCInfo(lcAccountManager) << "Copy settings" << oCSettings->allKeys().join(", "); settings = std::move(oCSettings); } - - break; + } else { + qCInfo(lcAccountManager) << "Copy settings" << oCSettings->allKeys().join(", "); + settings = std::move(oCSettings); } + + break; + } else { + qCInfo(lcAccountManager) << "Migrate: could not read old config " << configFile; } } } From 14bd744df666206ceac59e54371d6a1fbe022f54 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 15 Dec 2022 13:29:51 +0100 Subject: [PATCH 7/9] Use std::make_unique rather than manually build unique_ptr for oCSettings Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 32cb3abc3..00098bc86 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -177,7 +177,7 @@ bool AccountManager::restoreFromLegacySettings() qCInfo(lcAccountManager) << "Migrate: checking old config " << configFile; - std::unique_ptr oCSettings(new QSettings(configFile, QSettings::IniFormat)); + auto oCSettings = std::make_unique(configFile, QSettings::IniFormat); if (oCSettings->status() != QSettings::Status::NoError) { qCInfo(lcAccountManager) << "Error reading legacy configuration file" << oCSettings->status(); } From 3b7bd6d26c5a4b8981fd5b1d9f373292523c53ff Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 15 Dec 2022 14:32:48 +0100 Subject: [PATCH 8/9] Constify groups variable Signed-off-by: Claudio Cambra --- src/gui/folderman.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 42cdcdfa2..44c5efdef 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -507,7 +507,7 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat // Check if the filename is equal to the group setting. If not, use the group // name as an alias. - QStringList groups = settings.childGroups(); + const auto groups = settings.childGroups(); if (groups.isEmpty()) { qCWarning(lcFolderMan) << "empty file:" << cfgFile.filePath(); return folder; From b0d048b0b83f5bf6dea012ebf1b8d87c51e8a280 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 15 Dec 2022 16:09:39 +0100 Subject: [PATCH 9/9] Fix conflicting definitions in anonymous namespace in Unity build Signed-off-by: Claudio Cambra --- src/gui/folder.cpp | 2 +- src/gui/folderman.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 3abb319ae..0ed956f27 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -49,7 +49,7 @@ namespace { #ifndef VERSION_C #define VERSION_C -constexpr auto versionC= "version"; +constexpr auto versionC = "version"; #endif } namespace OCC { diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 44c5efdef..b6f9758dc 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -39,9 +39,9 @@ #include namespace { -constexpr auto accountsC = "Accounts"; -constexpr auto foldersC = "Folders"; -constexpr auto versionC = "version"; +constexpr auto settingsAccountsC = "Accounts"; +constexpr auto settingsFoldersC = "Folders"; +constexpr auto settingsVersionC = "version"; constexpr auto maxFoldersVersion = 1; } @@ -322,7 +322,7 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, f->switchToVirtualFiles(); } // Migrate the old "usePlaceholders" setting to the root folder pin state - if (settings.value(QLatin1String(versionC), 1).toInt() == 1 + if (settings.value(QLatin1String(settingsVersionC), 1).toInt() == 1 && settings.value(QLatin1String("usePlaceholders"), false).toBool()) { qCInfo(lcFolderMan) << "Migrate: From usePlaceholders to PinState::OnlineOnly"; f->setRootPinState(PinState::OnlineOnly); @@ -377,11 +377,11 @@ void FolderMan::backwardMigrationSettingsKeys(QStringList *deleteKeys, QStringLi auto processSubgroup = [&](const QString &name) { settings->beginGroup(name); - const int foldersVersion = settings->value(QLatin1String(versionC), 1).toInt(); + const int foldersVersion = settings->value(QLatin1String(settingsVersionC), 1).toInt(); if (foldersVersion <= maxFoldersVersion) { foreach (const auto &folderAlias, settings->childGroups()) { settings->beginGroup(folderAlias); - const int folderVersion = settings->value(QLatin1String(versionC), 1).toInt(); + const int folderVersion = settings->value(QLatin1String(settingsVersionC), 1).toInt(); if (folderVersion > FolderDefinition::maxSettingsVersion()) { ignoreKeys->append(settings->group()); } @@ -518,12 +518,12 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat return nullptr; } - settings.beginGroup(accountsC); + settings.beginGroup(settingsAccountsC); const auto rootChildGroups = settings.childGroups(); for (const auto &accountId : rootChildGroups) { qCDebug(lcFolderMan) << "try to migrate accountId:" << accountId; settings.beginGroup(accountId); - settings.beginGroup(foldersC); + settings.beginGroup(settingsFoldersC); if (settings.childGroups().isEmpty()) { continue;