Merge pull request #3955 from nextcloud/feature/enforceVFS

add an option to enforce use of virtual files sync folder
This commit is contained in:
Matthieu Gallien 2021-11-08 14:26:32 +01:00 committed by GitHub
commit 4bd9972d46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 53 additions and 1 deletions

View file

@ -34,6 +34,7 @@ option( BUILD_UPDATER "Build updater" OFF )
option( WITH_PROVIDERS "Build with providers list" ON ) option( WITH_PROVIDERS "Build with providers list" ON )
option( ENFORCE_VIRTUAL_FILES_SYNC_FOLDER "Enforce use of virtual files sync folder when available" OFF )
## Theming options ## Theming options
set(NEXTCLOUD_BACKGROUND_COLOR "#0082c9" CACHE STRING "Default Nextcloud background color") set(NEXTCLOUD_BACKGROUND_COLOR "#0082c9" CACHE STRING "Default Nextcloud background color")

View file

@ -32,6 +32,7 @@
#cmakedefine APPLICATION_OCSP_STAPLING_ENABLED "@APPLICATION_OCSP_STAPLING_ENABLED@" #cmakedefine APPLICATION_OCSP_STAPLING_ENABLED "@APPLICATION_OCSP_STAPLING_ENABLED@"
#cmakedefine APPLICATION_FORBID_BAD_SSL "@APPLICATION_FORBID_BAD_SSL@" #cmakedefine APPLICATION_FORBID_BAD_SSL "@APPLICATION_FORBID_BAD_SSL@"
#define APPLICATION_DOTVIRTUALFILE_SUFFIX "." APPLICATION_VIRTUALFILE_SUFFIX #define APPLICATION_DOTVIRTUALFILE_SUFFIX "." APPLICATION_VIRTUALFILE_SUFFIX
#cmakedefine01 ENFORCE_VIRTUAL_FILES_SYNC_FOLDER
#cmakedefine ZLIB_FOUND @ZLIB_FOUND@ #cmakedefine ZLIB_FOUND @ZLIB_FOUND@

View file

@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "config.h"
#include "vfs.h" #include "vfs.h"
#include "plugin.h" #include "plugin.h"
#include "version.h" #include "version.h"

View file

@ -593,6 +593,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
ac = menu->addAction(tr("Disable virtual file support …")); ac = menu->addAction(tr("Disable virtual file support …"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotDisableVfsCurrentFolder); connect(ac, &QAction::triggered, this, &AccountSettings::slotDisableVfsCurrentFolder);
ac->setDisabled(Theme::instance()->enforceVirtualFilesSyncFolder());
} }
if (Theme::instance()->showVirtualFilesOption() if (Theme::instance()->showVirtualFilesOption()

View file

@ -671,7 +671,7 @@ void Folder::setVirtualFilesEnabled(bool enabled)
startVfs(); startVfs();
if (newMode != Vfs::Off) { if (newMode != Vfs::Off) {
_saveInFoldersWithPlaceholders = true; _saveInFoldersWithPlaceholders = true;
SyncEngine::switchToVirtualFiles(path(), _journal, *_vfs); switchToVirtualFiles();
} }
saveToSettings(); saveToSettings();
} }
@ -688,6 +688,11 @@ void Folder::setRootPinState(PinState state)
slotNextSyncFullLocalDiscovery(); slotNextSyncFullLocalDiscovery();
} }
void Folder::switchToVirtualFiles()
{
SyncEngine::switchToVirtualFiles(path(), _journal, *_vfs);
}
bool Folder::supportsSelectiveSync() const bool Folder::supportsSelectiveSync() const
{ {
return !virtualFilesEnabled() && !isVfsOnOffSwitchPending(); return !virtualFilesEnabled() && !isVfsOnOffSwitchPending();

View file

@ -287,6 +287,8 @@ public:
bool isVfsOnOffSwitchPending() const { return _vfsOnOffPending; } bool isVfsOnOffSwitchPending() const { return _vfsOnOffPending; }
void setVfsOnOffSwitchPending(bool pending) { _vfsOnOffPending = pending; } void setVfsOnOffSwitchPending(bool pending) { _vfsOnOffPending = pending; }
void switchToVirtualFiles();
/** Whether this folder should show selective sync ui */ /** Whether this folder should show selective sync ui */
bool supportsSelectiveSync() const; bool supportsSelectiveSync() const;

View file

@ -292,6 +292,11 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account,
SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folderDefinition.absoluteJournalPath()); SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folderDefinition.absoluteJournalPath());
} }
const auto switchToVfs = isSwitchToVfsNeeded(folderDefinition);
if (switchToVfs) {
folderDefinition.virtualFilesMode = bestAvailableVfsMode();
}
auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode); auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode);
if (!vfs) { if (!vfs) {
// TODO: Must do better error handling // TODO: Must do better error handling
@ -300,6 +305,9 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account,
Folder *f = addFolderInternal(std::move(folderDefinition), account.data(), std::move(vfs)); Folder *f = addFolderInternal(std::move(folderDefinition), account.data(), std::move(vfs));
if (f) { if (f) {
if (switchToVfs) {
f->switchToVirtualFiles();
}
// Migrate the old "usePlaceholders" setting to the root folder pin state // Migrate the old "usePlaceholders" setting to the root folder pin state
if (settings.value(QLatin1String(versionC), 1).toInt() == 1 if (settings.value(QLatin1String(versionC), 1).toInt() == 1
&& settings.value(QLatin1String("usePlaceholders"), false).toBool()) { && settings.value(QLatin1String("usePlaceholders"), false).toBool()) {
@ -837,6 +845,19 @@ bool FolderMan::pushNotificationsFilesReady(Account *account)
return pushFilesAvailable && pushNotifications && pushNotifications->isReady(); return pushFilesAvailable && pushNotifications && pushNotifications->isReady();
} }
bool FolderMan::isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const
{
auto result = false;
if (ENFORCE_VIRTUAL_FILES_SYNC_FOLDER &&
folderDefinition.virtualFilesMode != bestAvailableVfsMode() &&
folderDefinition.virtualFilesMode == Vfs::Off &&
OCC::Theme::instance()->showVirtualFilesOption()) {
result = true;
}
return result;
}
void FolderMan::slotEtagPollTimerTimeout() void FolderMan::slotEtagPollTimerTimeout()
{ {
qCInfo(lcFolderMan) << "Etag poll timer timeout"; qCInfo(lcFolderMan) << "Etag poll timer timeout";

View file

@ -324,6 +324,8 @@ private:
bool pushNotificationsFilesReady(Account *account); bool pushNotificationsFilesReady(Account *account);
bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const;
QSet<Folder *> _disabledFolders; QSet<Folder *> _disabledFolders;
Folder::Map _folderMap; Folder::Map _folderMap;
QString _folderConfigPath; QString _folderConfigPath;

View file

@ -545,6 +545,11 @@ void FolderWizardSelectiveSync::initializePage()
_virtualFilesCheckBox->setChecked(bestAvailableVfsMode() == Vfs::WindowsCfApi); _virtualFilesCheckBox->setChecked(bestAvailableVfsMode() == Vfs::WindowsCfApi);
_virtualFilesCheckBox->setEnabled(true); _virtualFilesCheckBox->setEnabled(true);
_virtualFilesCheckBox->setText(tr("Use virtual files instead of downloading content immediately %1").arg(bestAvailableVfsMode() == Vfs::WindowsCfApi ? QString() : tr("(experimental)"))); _virtualFilesCheckBox->setText(tr("Use virtual files instead of downloading content immediately %1").arg(bestAvailableVfsMode() == Vfs::WindowsCfApi ? QString() : tr("(experimental)")));
if (Theme::instance()->enforceVirtualFilesSyncFolder()) {
_virtualFilesCheckBox->setChecked(true);
_virtualFilesCheckBox->setDisabled(true);
}
} }
// //
} }

View file

@ -59,6 +59,11 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage(OwncloudWizard *wizard)
connect(_ui.pbSelectLocalFolder, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSelectFolder); connect(_ui.pbSelectLocalFolder, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSelectFolder);
setButtonText(QWizard::FinishButton, tr("Connect")); setButtonText(QWizard::FinishButton, tr("Connect"));
if (Theme::instance()->enforceVirtualFilesSyncFolder()) {
_ui.rSyncEverything->setDisabled(true);
_ui.rSelectiveSync->setDisabled(true);
}
connect(_ui.rSyncEverything, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSyncEverythingClicked); connect(_ui.rSyncEverything, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSyncEverythingClicked);
connect(_ui.rSelectiveSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSelectiveSyncClicked); connect(_ui.rSelectiveSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSelectiveSyncClicked);
connect(_ui.rVirtualFileSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotVirtualFileSyncClicked); connect(_ui.rVirtualFileSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotVirtualFileSyncClicked);

View file

@ -859,6 +859,12 @@ bool Theme::showVirtualFilesOption() const
return ConfigFile().showExperimentalOptions() || vfsMode == Vfs::WindowsCfApi; return ConfigFile().showExperimentalOptions() || vfsMode == Vfs::WindowsCfApi;
} }
bool Theme::enforceVirtualFilesSyncFolder() const
{
const auto vfsMode = bestAvailableVfsMode();
return ENFORCE_VIRTUAL_FILES_SYNC_FOLDER && vfsMode != OCC::Vfs::Off;
}
QColor Theme::errorBoxTextColor() const QColor Theme::errorBoxTextColor() const
{ {
return QColor{"white"}; return QColor{"white"};

View file

@ -565,6 +565,8 @@ public:
*/ */
virtual bool showVirtualFilesOption() const; virtual bool showVirtualFilesOption() const;
virtual bool enforceVirtualFilesSyncFolder() const;
/** @return color for the ErrorBox text. */ /** @return color for the ErrorBox text. */
virtual QColor errorBoxTextColor() const; virtual QColor errorBoxTextColor() const;