Vfs: Retain existing data when enabling vfs #7302

Previously all local data was deleted because the root folder was marked
as OnlineOnly.
This commit is contained in:
Christian Kamm 2019-07-10 13:34:17 +02:00 committed by Kevin Ottens
parent 92f6d866e1
commit fc52c5d0cd
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
5 changed files with 21 additions and 19 deletions

View 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();
}

View 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.

View 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

View 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

View 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());