From: Christian Kamm Date: Mon, 14 Jan 2019 14:48:08 +0000 (+0100) Subject: Vfs: Switch on/off only when sync isn't running #6936 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~329 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b7079289c2c926dbbcea9a9fce0f10db7b1272f4;p=nextcloud-desktop.git Vfs: Switch on/off only when sync isn't running #6936 Avoids some situations that might cause data loss. --- diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index cfe3a1c8e..da939cf8d 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -457,7 +457,8 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) if (Theme::instance()->showVirtualFilesOption() && !folder->supportsVirtualFiles() - && bestAvailableVfsMode() != Vfs::Off) { + && bestAvailableVfsMode() != Vfs::Off + && !folder->isVfsOnOffSwitchPending()) { ac = menu->addAction(tr("Enable virtual file support (experimental)...")); connect(ac, &QAction::triggered, this, &AccountSettings::slotEnableVfsCurrentFolder); } @@ -648,27 +649,43 @@ void AccountSettings::slotEnableVfsCurrentFolder() if (!enable || !folder) return; - qCInfo(lcAccountSettings) << "Enabling vfs support for folder" << folder->path(); + // It is unsafe to switch on vfs while a sync is running - wait if necessary. + auto connection = std::make_shared(); + auto switchVfsOn = [folder, connection, this]() { + if (*connection) + QObject::disconnect(*connection); - // Wipe selective sync blacklist - bool ok = false; - auto oldBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok); - folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {}); - for (const auto &entry : oldBlacklist) { - folder->journalDb()->avoidReadFromDbOnNextSync(entry); - } + qCInfo(lcAccountSettings) << "Enabling vfs support for folder" << folder->path(); + + // Wipe selective sync blacklist + bool ok = false; + auto oldBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok); + folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {}); + for (const auto &entry : oldBlacklist) { + folder->journalDb()->avoidReadFromDbOnNextSync(entry); + } + + // Change the folder vfs mode and load the plugin + folder->setSupportsVirtualFiles(true); + folder->setVfsOnOffSwitchPending(false); - // Change the folder vfs mode and load the plugin - folder->setSupportsVirtualFiles(true); + // Wipe pin states to be sure + folder->journalDb()->wipePinStateForPathAndBelow(""); + folder->journalDb()->setPinStateForPath("", PinState::OnlineOnly); - // Wipe pin states to be sure - folder->journalDb()->wipePinStateForPathAndBelow(""); - folder->journalDb()->setPinStateForPath("", PinState::OnlineOnly); + FolderMan::instance()->scheduleFolder(folder); - FolderMan::instance()->scheduleFolder(folder); + _ui->_folderList->doItemsLayout(); + }; - // Update the ui: no selective sync, vfs indicator; size changed - _ui->_folderList->doItemsLayout(); + if (folder->isSyncRunning()) { + *connection = connect(folder, &Folder::syncFinished, this, switchVfsOn); + folder->setVfsOnOffSwitchPending(true); + folder->slotTerminateSync(); + _ui->_folderList->doItemsLayout(); + } else { + switchVfsOn(); + } }); } @@ -687,7 +704,9 @@ void AccountSettings::slotDisableVfsCurrentFolder() "are currently marked as 'available online only' will be downloaded." "\n\n" "The only advantage of disabling virtual file support is that the selective sync feature " - "will become available again.")); + "will become available again." + "\n\n" + "This action will abort any currently running synchronization.")); msgBox->addButton(tr("Disable support"), QMessageBox::AcceptRole); msgBox->addButton(tr("Cancel"), QMessageBox::RejectRole); connect(msgBox, &QMessageBox::finished, msgBox, [this, msgBox, folder](int result) { @@ -695,20 +714,36 @@ void AccountSettings::slotDisableVfsCurrentFolder() if (result != QMessageBox::AcceptRole || !folder) return; - qCInfo(lcAccountSettings) << "Disabling vfs support for folder" << folder->path(); + // It is unsafe to switch off vfs while a sync is running - wait if necessary. + auto connection = std::make_shared(); + auto switchVfsOff = [folder, connection, this]() { + if (*connection) + QObject::disconnect(*connection); + + qCInfo(lcAccountSettings) << "Disabling vfs support for folder" << folder->path(); - // Also wipes virtual files, schedules remote discovery - folder->setSupportsVirtualFiles(false); + // Also wipes virtual files, schedules remote discovery + folder->setSupportsVirtualFiles(false); + folder->setVfsOnOffSwitchPending(false); - // Wipe pin states and selective sync db - folder->journalDb()->wipePinStateForPathAndBelow(""); - folder->journalDb()->setPinStateForPath("", PinState::AlwaysLocal); - folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {}); + // Wipe pin states and selective sync db + folder->journalDb()->wipePinStateForPathAndBelow(""); + folder->journalDb()->setPinStateForPath("", PinState::AlwaysLocal); + folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {}); - FolderMan::instance()->scheduleFolder(folder); + FolderMan::instance()->scheduleFolder(folder); - // Update the ui: no selective sync, vfs indicator; size changed - _ui->_folderList->doItemsLayout(); + _ui->_folderList->doItemsLayout(); + }; + + if (folder->isSyncRunning()) { + *connection = connect(folder, &Folder::syncFinished, this, switchVfsOff); + folder->setVfsOnOffSwitchPending(true); + folder->slotTerminateSync(); + _ui->_folderList->doItemsLayout(); + } else { + switchVfsOff(); + } }); msgBox->open(); } diff --git a/src/gui/wizard/owncloudwizard.cpp b/src/gui/wizard/owncloudwizard.cpp index 7079f2fc1..b9c33957d 100644 --- a/src/gui/wizard/owncloudwizard.cpp +++ b/src/gui/wizard/owncloudwizard.cpp @@ -341,6 +341,8 @@ void OwncloudWizard::askExperimentalVirtualFilesFeature(const std::function