Skip to content

Commit

Permalink
VirtualFiles: Ensure the target location supports vfs
Browse files Browse the repository at this point in the history
Fixes: #8131
  • Loading branch information
TheOneRing committed Oct 21, 2020
1 parent dffe08c commit 7728c01
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 14 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/8131
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Check whether the local folder supports the virtual file system

The Windows virtual file system requires NTFS, we now ensure that the folder is
using NTFS before we continue.

https://github.com/owncloud/client/issues/8131
18 changes: 18 additions & 0 deletions src/common/vfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "version.h"
#include "syncjournaldb.h"

#include "common/filesystembase.h"

#include <QPluginLoader>
#include <QLoggingCategory>

Expand Down Expand Up @@ -60,6 +62,22 @@ Optional<Vfs::Mode> Vfs::modeFromString(const QString &str)
return {};
}

Result<bool, QString> Vfs::checkAvailability(const QString &path)
{
const auto mode = bestAvailableVfsMode();
#ifdef Q_OS_WIN
if (mode == Mode::WindowsCfApi) {
const auto fs = FileSystem::fileSystemForPath(path);
if (fs != QLatin1String("NTFS")) {
return tr("The Virtual filesystem feature requires a NTFS file system, %1 is using %2").arg(path, fs);
}
}
#else
Q_UNUSED(path);
#endif
return true;
}

void Vfs::start(const VfsSetupParams &params)
{
_setupParams = params;
Expand Down
2 changes: 2 additions & 0 deletions src/common/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class OCSYNC_EXPORT Vfs : public QObject
static QString modeToString(Mode mode);
static Optional<Mode> modeFromString(const QString &str);

static Result<bool, QString> checkAvailability(const QString &path);

enum class AvailabilityError
{
// Availability can't be retrieved due to db error
Expand Down
8 changes: 4 additions & 4 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
ac = menu->addAction(tr("Remove folder sync connection"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotRemoveCurrentFolder);

if (folder->supportsVirtualFiles()) {
if (folder->virtualFilesEnabled()) {
auto availabilityMenu = menu->addMenu(tr("Availability"));
auto availability = folder->vfs().availability(QString());
if (availability) {
Expand All @@ -337,7 +337,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
}

if (Theme::instance()->showVirtualFilesOption()
&& !folder->supportsVirtualFiles()) {
&& !folder->virtualFilesEnabled() && Vfs::checkAvailability(folder->path())) {
const auto mode = bestAvailableVfsMode();
if (mode == Vfs::WindowsCfApi || Theme::instance()->enableExperimentalFeatures()) {
ac = menu->addAction(tr("Enable virtual file support%1...").arg(mode == Vfs::WindowsCfApi ? QString() : tr(" (experimental)")));
Expand Down Expand Up @@ -562,7 +562,7 @@ void AccountSettings::slotEnableVfsCurrentFolder()
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {});

// Change the folder vfs mode and load the plugin
folder->setSupportsVirtualFiles(true);
folder->setVirtualFilesEnabled(true);
folder->setVfsOnOffSwitchPending(false);

// Setting to Unspecified retains existing data.
Expand Down Expand Up @@ -630,7 +630,7 @@ void AccountSettings::slotDisableVfsCurrentFolder()
qCInfo(lcAccountSettings) << "Disabling vfs support for folder" << folder->path();

// Also wipes virtual files, schedules remote discovery
folder->setSupportsVirtualFiles(false);
folder->setVirtualFilesEnabled(false);
folder->setVfsOnOffSwitchPending(false);

// Wipe pin states and selective sync db
Expand Down
8 changes: 4 additions & 4 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ void Folder::implicitlyHydrateFile(const QString &relativepath)
slotScheduleThisFolder();
}

void Folder::setSupportsVirtualFiles(bool enabled)
void Folder::setVirtualFilesEnabled(bool enabled)
{
Vfs::Mode newMode = _definition.virtualFilesMode;
if (enabled && _definition.virtualFilesMode == Vfs::Off) {
Expand Down Expand Up @@ -658,7 +658,7 @@ void Folder::setRootPinState(PinState state)

bool Folder::supportsSelectiveSync() const
{
return !supportsVirtualFiles() && !isVfsOnOffSwitchPending();
return !virtualFilesEnabled() && !isVfsOnOffSwitchPending();
}

void Folder::saveToSettings() const
Expand All @@ -678,7 +678,7 @@ void Folder::saveToSettings() const
}
}

if (supportsVirtualFiles() || _saveInFoldersWithPlaceholders) {
if (virtualFilesEnabled() || _saveInFoldersWithPlaceholders) {
// If virtual files are enabled or even were enabled at some point,
// save the folder to a group that will not be read by older (<2.5.0) clients.
// The name is from when virtual files were called placeholders.
Expand Down Expand Up @@ -1183,7 +1183,7 @@ void Folder::registerFolderWatcher()
_folderWatcher->startNotificatonTest(path() + QLatin1String(".owncloudsync.log"));
}

bool Folder::supportsVirtualFiles() const
bool Folder::virtualFilesEnabled() const
{
return _definition.virtualFilesMode != Vfs::Off && !isVfsOnOffSwitchPending();
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ class Folder : public QObject
* and never have an automatic virtual file. But when it's on, the shell context menu will allow
* users to make existing files virtual.
*/
bool supportsVirtualFiles() const;
void setSupportsVirtualFiles(bool enabled);
bool virtualFilesEnabled() const;
void setVirtualFilesEnabled(bool enabled);

void setRootPinState(PinState state);

Expand Down
4 changes: 2 additions & 2 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
case FolderStatusDelegate::FolderErrorMsg:
return f->syncResult().errorStrings();
case FolderStatusDelegate::FolderInfoMsg:
return f->supportsVirtualFiles() && f->vfs().mode() != Vfs::Mode::WindowsCfApi
return f->virtualFilesEnabled() && f->vfs().mode() != Vfs::Mode::WindowsCfApi
? QStringList(tr("Virtual file support is enabled."))
: QStringList();
case FolderStatusDelegate::SyncRunning:
Expand Down Expand Up @@ -275,7 +275,7 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
case FolderStatusDelegate::SyncProgressOverallString:
return progress._overallSyncString;
case FolderStatusDelegate::FolderSyncText:
if (f->supportsVirtualFiles()) {
if (f->virtualFilesEnabled()) {
return tr("Synchronizing VirtualFiles with local folder");
} else {
return tr("Synchronizing with local folder");
Expand Down
12 changes: 11 additions & 1 deletion src/gui/folderwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QVBoxLayout>
#include <QEvent>
#include <QCheckBox>
#include <QMessageBox>

#include <stdlib.h>

Expand Down Expand Up @@ -511,7 +512,16 @@ void FolderWizardSelectiveSync::initializePage()

bool FolderWizardSelectiveSync::validatePage()
{
bool useVirtualFiles = _virtualFilesCheckBox && _virtualFilesCheckBox->isChecked();
const bool useVirtualFiles = _virtualFilesCheckBox && _virtualFilesCheckBox->isChecked();
if (useVirtualFiles) {
const auto availability = Vfs::checkAvailability(wizard()->field(QStringLiteral("sourceFolder")).toString());
if (!availability) {
auto msg = new QMessageBox(QMessageBox::Warning, tr("Virtual files are not available for the selected folder"), availability.error(), QMessageBox::Ok, this);
msg->setAttribute(Qt::WA_DeleteOnClose);
msg->open();
return false;
}
}
wizard()->setProperty("selectiveSyncBlackList", useVirtualFiles ? QVariant() : QVariant(_selectiveSync->createBlackList()));
wizard()->setProperty("useVirtualFiles", QVariant(useVirtualFiles));
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe

// File availability actions
if (folder
&& folder->supportsVirtualFiles()
&& folder->virtualFilesEnabled()
&& folder->vfs().socketApiPinStateActionsShown()) {
OC_ENFORCE(!files.isEmpty());

Expand Down
10 changes: 10 additions & 0 deletions src/gui/wizard/owncloudadvancedsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,16 @@ bool OwncloudAdvancedSetupPage::validatePage()
return true;
}

if (useVirtualFileSync()) {
const auto availability = Vfs::checkAvailability(localFolder());
if (!availability) {
auto msg = new QMessageBox(QMessageBox::Warning, tr("Virtual files are not available for the selected folder"), availability.error(), QMessageBox::Ok, this);
msg->setAttribute(Qt::WA_DeleteOnClose);
msg->open();
return false;
}
}

if (!_created) {
setErrorString(QString());
_checking = true;
Expand Down

2 comments on commit 7728c01

@deajan
Copy link

@deajan deajan commented on 7728c01 Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if that's not the right place to comment, but shouldn't the test against VFS support allow 'NTFS' and also 'ReFS' ?

@TheOneRing
Copy link
Member Author

@TheOneRing TheOneRing commented on 7728c01 Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://en.wikipedia.org/wiki/ReFS

The ability to create ReFS volumes was removed in Windows 10's 2017 Fall Creators Update for all editions except Enterprise and Pro for Workstations.[4]

Currently I don't have a test system and in general I'm not sure how common this would be.
If you need ReFS support, please open an issue.

Please sign in to comment.