Placeholders: Save to key that's invisible to <2.5 clients #6504
authorChristian Kamm <mail@ckamm.de>
Wed, 2 May 2018 10:38:03 +0000 (12:38 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:57:52 +0000 (10:57 +0100)
src/gui/folder.cpp
src/gui/folderman.cpp

index 1042d2f48daa915f0d9c12f5ccc579780dc73375..3b87871a4a0e5f9b4d3a40bca9cf76959950d243 100644 (file)
@@ -546,26 +546,30 @@ void Folder::saveToSettings() const
     removeFromSettings();
 
     auto settings = _accountState->settings();
+    QString settingsGroup = QStringLiteral("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.
+    // True if the folder path appears in only one account
     const auto folderMap = FolderMan::instance()->map();
     const auto oneAccountOnly = std::none_of(folderMap.cbegin(), folderMap.cend(), [this](const auto *other) {
         return other != this && other->cleanPath() == this->cleanPath();
     });
 
-    bool compatible = _saveBackwardsCompatible || oneAccountOnly;
-
-    if (compatible) {
-        settings->beginGroup(QLatin1String("Folders"));
-    } else {
-        settings->beginGroup(QLatin1String("Multifolders"));
+    if (_definition.usePlaceholders) {
+        // If placeholders are enabled, save the folder to a group
+        // that will not be read by older (<2.5.0) clients.
+        settingsGroup = QStringLiteral("FoldersWithPlaceholders");
+    } else if (_saveBackwardsCompatible || oneAccountOnly) {
+        // 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);
 
     settings->sync();
@@ -580,6 +584,9 @@ void Folder::removeFromSettings() const
     settings->endGroup();
     settings->beginGroup(QLatin1String("Multifolders"));
     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
index 818337687e5b78c75e50bcb92c5850862b85776e..a4ba88872de4abe20a55d0dc15c180d579ac35c8 100644 (file)
@@ -187,6 +187,11 @@ int FolderMan::setupFolders()
         setupFoldersHelper(*settings, account, false);
         settings->endGroup();
 
+        // See Folder::saveToSettings for details about why this exists.
+        settings->beginGroup(QLatin1String("FoldersWithPlaceholders"));
+        setupFoldersHelper(*settings, account, false);
+        settings->endGroup();
+
         settings->endGroup(); // <account>
     }