Placeholders: Save to key that's invisible to <2.5 clients #6504

This commit is contained in:
Christian Kamm 2018-05-02 12:38:03 +02:00 committed by Kevin Ottens
parent 3272f3b72b
commit 27b65cbc69
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
2 changed files with 25 additions and 13 deletions

View file

@ -546,26 +546,30 @@ void Folder::saveToSettings() const
removeFromSettings(); removeFromSettings();
auto settings = _accountState->settings(); auto settings = _accountState->settings();
QString settingsGroup = QStringLiteral("Multifolders");
// The folder is saved to backwards-compatible "Folders" // True if the folder path appears in only one account
// section only if it has the migrate flag set (i.e. was in
// there before) or if the folder is the only one for the
// given target path.
// This ensures that older clients will not read a configuration
// where two folders for different accounts point at the same
// local folders.
const auto folderMap = FolderMan::instance()->map(); const auto folderMap = FolderMan::instance()->map();
const auto oneAccountOnly = std::none_of(folderMap.cbegin(), folderMap.cend(), [this](const auto *other) { const auto oneAccountOnly = std::none_of(folderMap.cbegin(), folderMap.cend(), [this](const auto *other) {
return other != this && other->cleanPath() == this->cleanPath(); return other != this && other->cleanPath() == this->cleanPath();
}); });
bool compatible = _saveBackwardsCompatible || oneAccountOnly; if (_definition.usePlaceholders) {
// If placeholders are enabled, save the folder to a group
if (compatible) { // that will not be read by older (<2.5.0) clients.
settings->beginGroup(QLatin1String("Folders")); settingsGroup = QStringLiteral("FoldersWithPlaceholders");
} else { } else if (_saveBackwardsCompatible || oneAccountOnly) {
settings->beginGroup(QLatin1String("Multifolders")); // The folder is saved to backwards-compatible "Folders"
// section only if it has the migrate flag set (i.e. was in
// there before) or if the folder is the only one for the
// given target path.
// This ensures that older clients will not read a configuration
// where two folders for different accounts point at the same
// local folders.
settingsGroup = QStringLiteral("Folders");
} }
settings->beginGroup(settingsGroup);
FolderDefinition::save(*settings, _definition); FolderDefinition::save(*settings, _definition);
settings->sync(); settings->sync();
@ -580,6 +584,9 @@ void Folder::removeFromSettings() const
settings->endGroup(); settings->endGroup();
settings->beginGroup(QLatin1String("Multifolders")); settings->beginGroup(QLatin1String("Multifolders"));
settings->remove(FolderMan::escapeAlias(_definition.alias)); settings->remove(FolderMan::escapeAlias(_definition.alias));
settings->endGroup();
settings->beginGroup(QLatin1String("FoldersWithPlaceholders"));
settings->remove(FolderMan::escapeAlias(_definition.alias));
} }
bool Folder::isFileExcludedAbsolute(const QString &fullPath) const bool Folder::isFileExcludedAbsolute(const QString &fullPath) const

View file

@ -187,6 +187,11 @@ int FolderMan::setupFolders()
setupFoldersHelper(*settings, account, false); setupFoldersHelper(*settings, account, false);
settings->endGroup(); settings->endGroup();
// See Folder::saveToSettings for details about why this exists.
settings->beginGroup(QLatin1String("FoldersWithPlaceholders"));
setupFoldersHelper(*settings, account, false);
settings->endGroup();
settings->endGroup(); // <account> settings->endGroup(); // <account>
} }