Vfs: Retain existing data when enabling vfs #7302
authorChristian Kamm <mail@ckamm.de>
Wed, 10 Jul 2019 11:34:17 +0000 (13:34 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:53 +0000 (10:58 +0100)
Previously all local data was deleted because the root folder was marked
as OnlineOnly.

src/gui/accountsettings.cpp
src/gui/folder.cpp
src/gui/folder.h
src/gui/folderman.cpp
src/gui/owncloudsetupwizard.cpp

index 7aa4c804115e36e7df7767852a7d922df01c3dc3..350626b50baa1ac710a21258b9af9850b5327ad4 100644 (file)
@@ -576,7 +576,7 @@ void AccountSettings::slotFolderWizardAccepted()
     Folder *f = folderMan->addFolder(_accountState, definition);
     if (f) {
         if (definition.virtualFilesMode != Vfs::Off && folderWizard->property("useVirtualFiles").toBool())
-            f->setNewFilesAreVirtual(true);
+            f->setRootPinState(PinState::OnlineOnly);
 
         f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, selectiveSyncBlackList);
 
@@ -673,17 +673,19 @@ void AccountSettings::slotEnableVfsCurrentFolder()
             bool ok = false;
             auto oldBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok);
             folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {});
-            for (const auto &entry : oldBlacklist) {
-                folder->journalDb()->schedulePathForRemoteDiscovery(entry);
-                folder->schedulePathForLocalDiscovery(entry);
-            }
 
             // Change the folder vfs mode and load the plugin
             folder->setSupportsVirtualFiles(true);
             folder->setVfsOnOffSwitchPending(false);
 
-            // Sets pin states to OnlineOnly everywhere
-            folder->setNewFilesAreVirtual(true);
+            // Setting to Unspecified retains existing data.
+            // Selective sync excluded folders become OnlineOnly.
+            folder->setRootPinState(PinState::Unspecified);
+            for (const auto &entry : oldBlacklist) {
+                folder->journalDb()->schedulePathForRemoteDiscovery(entry);
+                folder->vfs().setPinState(entry, PinState::OnlineOnly);
+            }
+            folder->slotNextSyncFullLocalDiscovery();
 
             FolderMan::instance()->scheduleFolder(folder);
 
@@ -739,7 +741,7 @@ void AccountSettings::slotDisableVfsCurrentFolder()
             folder->setVfsOnOffSwitchPending(false);
 
             // Wipe pin states and selective sync db
-            folder->setNewFilesAreVirtual(false);
+            folder->setRootPinState(PinState::AlwaysLocal);
             folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {});
 
             FolderMan::instance()->scheduleFolder(folder);
@@ -770,7 +772,7 @@ void AccountSettings::slotSetCurrentFolderAvailability(PinState state)
         return;
 
     // similar to socket api: sets pin state recursively and sync
-    folder->setNewFilesAreVirtual(state == PinState::OnlineOnly);
+    folder->setRootPinState(state);
     folder->scheduleThisFolderSoon();
 }
 
index 88a1e59de491a4575a27fbf8e088ca4795bd444a..b77abe387cf6b798faf7da129c158aff5f88de50 100644 (file)
@@ -664,10 +664,9 @@ bool Folder::newFilesAreVirtual() const
     return pinState && *pinState == PinState::OnlineOnly;
 }
 
-void Folder::setNewFilesAreVirtual(bool enabled)
+void Folder::setRootPinState(PinState state)
 {
-    const auto newPin = enabled ? PinState::OnlineOnly : PinState::AlwaysLocal;
-    _vfs->setPinState(QString(), newPin);
+    _vfs->setPinState(QString(), state);
 
     // We don't actually need discovery, but it's important to recurse
     // into all folders, so the changes can be applied.
index a88ead00d3a080f7d76a2ef083198d8de6523866..92ad664ccb497f7c843dd5a6f9917d97fbcd0e40 100644 (file)
@@ -275,10 +275,11 @@ public:
 
     /** whether new remote files shall become virtual locally
      *
-     * This is the root folder pin state and can be overridden by explicit subfolder pin states.
+     * This happens when the root folder pin state is OnlineOnly, but can be
+     * overridden by explicit subfolder pin states.
      */
     bool newFilesAreVirtual() const;
-    void setNewFilesAreVirtual(bool enabled);
+    void setRootPinState(PinState state);
 
     /** Whether user desires a switch that couldn't be executed yet, see member */
     bool isVfsOnOffSwitchPending() const { return _vfsOnOffPending; }
@@ -356,6 +357,9 @@ public slots:
      */
     void schedulePathForLocalDiscovery(const QString &relativePath);
 
+    /** Ensures that the next sync performs a full local discovery. */
+    void slotNextSyncFullLocalDiscovery();
+
 private slots:
     void slotSyncStarted();
     void slotSyncFinished(bool);
@@ -382,9 +386,6 @@ private slots:
      */
     void slotScheduleThisFolder();
 
-    /** Ensures that the next sync performs a full local discovery. */
-    void slotNextSyncFullLocalDiscovery();
-
     /** Adjust sync result based on conflict data from IssuesWidget.
      *
      * This is pretty awkward, but IssuesWidget just keeps better track
index 180cebbd908ad6fc8c29f84e8743d0706c773e9e..0427fa99504dbb39810a365c0ac5daf191ab4ce0 100644 (file)
@@ -297,7 +297,7 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account,
                 // Migrate the old "usePlaceholders" setting to the root folder pin state
                 if (settings.value(QLatin1String(versionC), 1).toInt() == 1
                     && settings.value(QLatin1String("usePlaceholders"), false).toBool()) {
-                    f->setNewFilesAreVirtual(true);
+                    f->setRootPinState(PinState::OnlineOnly);
                 }
 
                 // Migration: Mark folders that shall be saved in a backwards-compatible way
index cb401cd56925c699f7b737455cbad874e8d35f3a..4e66fad782cc260f2aedf774c8ea67b6637e5e15 100644 (file)
@@ -660,7 +660,7 @@ void OwncloudSetupWizard::slotAssistantFinished(int result)
             auto f = folderMan->addFolder(account, folderDefinition);
             if (f) {
                 if (folderDefinition.virtualFilesMode != Vfs::Off && _ocWizard->useVirtualFileSync())
-                    f->setNewFilesAreVirtual(true);
+                    f->setRootPinState(PinState::OnlineOnly);
 
                 f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
                     _ocWizard->selectiveSyncBlacklist());