Settings: Make FoldersWithPlaceholders group sticky
authorChristian Kamm <mail@ckamm.de>
Mon, 29 Oct 2018 11:31:39 +0000 (12:31 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:15 +0000 (10:58 +0100)
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
src/gui/folder.h
src/gui/folderman.cpp
src/gui/folderman.h

index 1d38acfcf8c8e78115b591c0d67676e03f3ddfe2..ebe9feb91c768f5125591a3a989153d0cb2f91c4 100644 (file)
@@ -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) {
index b63be42d124fc1b2dbe62c25c2517545419fb57f..39baa989efb7eee438f30f00dd262d108fb9d7ee 100644 (file)
@@ -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.
index fd96392417e415a9c859d5852f8e57be32d3a60e..a0626725893c80c5252fc4ffaf8d2387434758cc 100644 (file)
@@ -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(); // <account>
     }
@@ -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);
             }
index f9e73199c996cc2330a8fcab0329dc47bb921ac2..057edd625e8bc5340ba676982cc6def3c7385c43 100644 (file)
@@ -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<Folder *> _disabledFolders;
     Folder::Map _folderMap;