From 7de453d4396bffbbc2affd6446885df4fc96b850 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Mon, 29 Oct 2018 12:31:39 +0100 Subject: [PATCH] Settings: Make FoldersWithPlaceholders group sticky If virtual files are disabled on a folder it might still have db entries or local virtual files that would confuse older client versions. --- src/gui/folder.cpp | 9 +++++---- src/gui/folder.h | 14 +++++++++++++- src/gui/folderman.cpp | 17 +++++++++-------- src/gui/folderman.h | 2 +- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 1d38acfcf..ebe9feb91 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -60,7 +60,6 @@ Folder::Folder(const FolderDefinition &definition, , _consecutiveFollowUpSyncs(0) , _journal(_definition.absoluteJournalPath()) , _fileLog(new SyncRunFileLog) - , _saveBackwardsCompatible(false) { _timeSinceLastSyncStart.start(); _timeSinceLastSyncDone.start(); @@ -548,6 +547,8 @@ void Folder::downloadVirtualFile(const QString &_relativepath) void Folder::setUseVirtualFiles(bool enabled) { _definition.useVirtualFiles = enabled; + if (enabled) + _saveInFoldersWithPlaceholders = true; saveToSettings(); } @@ -565,9 +566,9 @@ void Folder::saveToSettings() const return other != this && other->cleanPath() == this->cleanPath(); }); - if (_definition.useVirtualFiles) { - // If virtual files are enabled, save the folder to a group - // that will not be read by older (<2.5.0) clients. + if (_definition.useVirtualFiles || _saveInFoldersWithPlaceholders) { + // If virtual files are enabled or even were enabled at some point, + // save the folder to a group that will not be read by older (<2.5.0) clients. // The name is from when virtual files were called placeholders. settingsGroup = QStringLiteral("FoldersWithPlaceholders"); } else if (_saveBackwardsCompatible || oneAccountOnly) { diff --git a/src/gui/folder.h b/src/gui/folder.h index b63be42d1..39baa989e 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -227,6 +227,9 @@ public: */ void setSaveBackwardsCompatible(bool save); + /** Used to have placeholders: save in placeholder config section */ + void setSaveInFoldersWithPlaceholders() { _saveInFoldersWithPlaceholders = true; } + /** * Sets up this folder's folderWatcher if possible. * @@ -388,7 +391,16 @@ private: * on the *first* Folder instance that was configured for each local * path. */ - bool _saveBackwardsCompatible; + bool _saveBackwardsCompatible = false; + + /** Whether the folder should be saved in that settings group + * + * If it was read from there it had virtual files enabled at some + * point and might still have db entries or suffix-virtual files even + * if they are disabled right now. This flag ensures folders that + * were in that group once never go back. + */ + bool _saveInFoldersWithPlaceholders = false; /** * Watches this folder's local directory for changes. diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index fd9639241..a06267258 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -186,22 +186,22 @@ int FolderMan::setupFolders() // The "backwardsCompatible" flag here is related to migrating old // database locations - auto process = [&](const QString &groupName, bool backwardsCompatible = false) { + auto process = [&](const QString &groupName, bool backwardsCompatible, bool foldersWithPlaceholders) { settings->beginGroup(groupName); if (skipSettingsKeys.contains(settings->group())) { // Should not happen: bad container keys should have been deleted qCWarning(lcFolderMan) << "Folder structure" << groupName << "is too new, ignoring"; } else { - setupFoldersHelper(*settings, account, backwardsCompatible, skipSettingsKeys); + setupFoldersHelper(*settings, account, skipSettingsKeys, backwardsCompatible, foldersWithPlaceholders); } settings->endGroup(); }; - process(QStringLiteral("Folders"), true); + process(QStringLiteral("Folders"), true, false); // See Folder::saveToSettings for details about why these exists. - process(QStringLiteral("Multifolders")); - process(QStringLiteral("FoldersWithPlaceholders")); + process(QStringLiteral("Multifolders"), false, false); + process(QStringLiteral("FoldersWithPlaceholders"), false, true); settings->endGroup(); // } @@ -211,7 +211,7 @@ int FolderMan::setupFolders() return _folderMap.size(); } -void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, bool backwardsCompatible, const QStringList &ignoreKeys) +void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, const QStringList &ignoreKeys, bool backwardsCompatible, bool foldersWithPlaceholders) { for (const auto &folderAlias : settings.childGroups()) { // Skip folders with too-new version @@ -285,9 +285,10 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, Folder *f = addFolderInternal(std::move(folderDefinition), account.data()); if (f) { // Migration: Mark folders that shall be saved in a backwards-compatible way - if (backwardsCompatible) { + if (backwardsCompatible) f->setSaveBackwardsCompatible(true); - } + if (foldersWithPlaceholders) + f->setSaveInFoldersWithPlaceholders(); scheduleFolder(f); emit folderSyncStateChange(f); } diff --git a/src/gui/folderman.h b/src/gui/folderman.h index f9e73199c..057edd625 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -305,7 +305,7 @@ private: // restarts the application (Linux only) void restartApplication(); - void setupFoldersHelper(QSettings &settings, AccountStatePtr account, bool backwardsCompatible, const QStringList &ignoreKeys); + void setupFoldersHelper(QSettings &settings, AccountStatePtr account, const QStringList &ignoreKeys, bool backwardsCompatible, bool foldersWithPlaceholders); QSet _disabledFolders; Folder::Map _folderMap; -- 2.30.2