Skip to content

Commit c1b87cb

Browse files
committed
refactor method of checking path for vfs support
killed deadwood renamed Vfs::checkAvailability and changed return type to simple string updated callers and added copious todo's related to this topic of having local paths that don't support vfs even when vfs is otherwise available. See DC-219 for that
1 parent 478629e commit c1b87cb

File tree

10 files changed

+75
-55
lines changed

10 files changed

+75
-55
lines changed

src/common/vfs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ QString Utility::enumToString(Vfs::Mode mode)
6868
}
6969
}
7070

71-
Result<void, QString> Vfs::checkAvailability(const QString &path, Vfs::Mode mode)
71+
QString Vfs::pathSupportDetail(const QString &path, Vfs::Mode mode)
7272
{
7373
#ifdef Q_OS_WIN
7474
if (mode == Mode::WindowsCfApi) {

src/common/vfs.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,17 @@ class OCSYNC_EXPORT Vfs : public QObject
125125

126126
static Mode modeFromString(const QString &str);
127127

128-
static Result<void, QString> checkAvailability(const QString &path, OCC::Vfs::Mode mode);
128+
/**
129+
* @brief pathSupportDetail - needs a better name but the concept is that this function checks to see if the path is supported for vfs.
130+
* if it is not supported the return string contains the "reason" it's not supported.
131+
* @param path to check to for support
132+
* @param mode which we want to check - note that the only arg that makes sense here at all is Vfs::WindowsCfApi
133+
* @return empty string if the mode is supported on the given path. If the string is not empty, it contains a string explaining the
134+
* reason the mode is not supported.
135+
*
136+
* as of this writing, the possible root reasons are: path is a drive, path is on a network drive, path fs is not ntfs.
137+
*/
138+
static QString pathSupportDetail(const QString &path, OCC::Vfs::Mode mode);
129139

130140
enum class AvailabilityError
131141
{

src/gui/FoldersGui/accountfolderscontroller.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -161,35 +161,35 @@ void AccountFoldersController::buildMenuActions()
161161
itemActions.push_back(_chooseSync);
162162
connect(_chooseSync, &QAction::triggered, this, &AccountFoldersController::onChooseSync);
163163

164-
165-
// Only show "Enable VFS" if a VFS mode is available
166-
/* const auto mode = VfsPluginManager::instance().bestAvailableVfsMode();
167-
if (mode == Vfs::WindowsCfApi) {
168-
_enableVfs = new QAction(tr("Enable virtual file support"), this);
169-
170-
if (FolderMan::instance()->checkVfsAvailability(folder->path(), mode)) {
171-
if (mode == Vfs::WindowsCfApi) {
172-
QAction *enableVfsAction = menu->addAction(tr("Enable virtual file support"));
173-
connect(enableVfsAction, &QAction::triggered, this, [folder, this] { slotEnableVfsCurrentFolder(folder); });
174-
}
175-
}
176-
};
177-
178-
if (Theme::instance()->showVirtualFilesOption()) {
179-
if (Theme::instance()->forceVirtualFilesOption()) {
180-
if (!folder->virtualFilesEnabled()) {
181-
// VFS is currently disabled, but is forced on by theming (e.g. due to a theme change)
182-
maybeShowEnableVfs();
164+
/* auto maybeShowEnableVfs = [folder, menu, this]() {
165+
// Only show "Enable VFS" if a VFS mode is available
166+
const auto mode = VfsPluginManager::instance().bestAvailableVfsMode();
167+
if (mode == Vfs::WindowsCfApi) {
168+
_enableVfs = new QAction(tr("Enable virtual file support"), this);
169+
170+
if (FolderMan::instance()->checkVfsAvailability(folder->path(), mode)) {
171+
if (mode == Vfs::WindowsCfApi) {
172+
QAction *enableVfsAction = menu->addAction(tr("Enable virtual file support"));
173+
connect(enableVfsAction, &QAction::triggered, this, [folder, this] { slotEnableVfsCurrentFolder(folder); });
174+
}
183175
}
184-
} else {
185-
if (folder->virtualFilesEnabled()) {
186-
menu->addAction(tr("Disable virtual file support"), this, [folder, this] { slotDisableVfsCurrentFolder(folder); });
176+
};
177+
178+
if (Theme::instance()->showVirtualFilesOption()) {
179+
if (Theme::instance()->forceVirtualFilesOption()) {
180+
if (!folder->virtualFilesEnabled()) {
181+
// VFS is currently disabled, but is forced on by theming (e.g. due to a theme change)
182+
maybeShowEnableVfs();
183+
}
187184
} else {
188-
maybeShowEnableVfs();
185+
if (folder->virtualFilesEnabled()) {
186+
menu->addAction(tr("Disable virtual file support"), this, [folder, this] { slotDisableVfsCurrentFolder(folder); });
187+
} else {
188+
maybeShowEnableVfs();
189+
}
189190
}
190-
}
191-
_enableVfs = new QAction(this);
192-
*/
191+
_enableVfs = new QAction(this);
192+
*/
193193

194194
connect(_view, &AccountFoldersView::requestActionsUpdate, this, &AccountFoldersController::updateActions);
195195
_view->setFolderActions(itemActions);
@@ -234,10 +234,10 @@ void AccountFoldersController::onEnableVfs()
234234
if (!_currentFolder || _currentFolder->virtualFilesEnabled() || VfsPluginManager::instance().bestAvailableVfsMode() != Vfs::WindowsCfApi)
235235
return;
236236

237-
qCInfo(lcAccountView) << "Enabling vfs support for folder" << folder->path();
237+
qCInfo(lcAccountFoldersController) << "Enabling vfs support for folder" << _currentFolder->path();
238238

239239
// Change the folder vfs mode and load the plugin
240-
folder->setVirtualFilesEnabled(true);
240+
_currentFolder->setVirtualFilesEnabled(true);
241241
}
242242

243243
void AccountFoldersController::onDisableVfs()
@@ -288,9 +288,9 @@ void AccountFoldersController::updateActions()
288288

289289
_removeSync->setEnabled(_currentFolder);
290290

291-
if (_toggleVfs) {
292-
_toggleVfs->setText(_currentFolder && _currentFolder->virtualFilesEnabled() ? tr("Disable virtual file support") : tr("Enable virtual file support");
293-
_toggleVfs->setEnabled();
291+
if (_enableVfs) {
292+
_enableVfs->setText(_currentFolder && _currentFolder->virtualFilesEnabled() ? tr("Disable virtual file support") : tr("Enable virtual file support"));
293+
_enableVfs->setEnabled(_currentFolder->canSync());
294294
}
295295

296296
_chooseSync->setEnabled(_currentFolder && _currentFolder->isAvailable() && !_currentFolder->virtualFilesEnabled());

src/gui/accountsettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void AccountSettings::slotCustomContextMenuRequested(Folder *folder)
226226
auto maybeShowEnableVfs = [folder, menu, this]() {
227227
// Only show "Enable VFS" if a VFS mode is available
228228
const auto mode = VfsPluginManager::instance().bestAvailableVfsMode();
229-
if (FolderMan::instance()->checkVfsAvailability(folder->path(), mode)) {
229+
if (Vfs::pathSupportDetail(folder->path(), mode).isEmpty()) {
230230
if (mode == Vfs::WindowsCfApi) {
231231
QAction *enableVfsAction = menu->addAction(tr("Enable virtual file support"));
232232
connect(enableVfsAction, &QAction::triggered, this, [folder, this] { slotEnableVfsCurrentFolder(folder); });

src/gui/folder.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,14 @@ void Folder::startVfs()
513513
OC_ENFORCE(_vfs);
514514
OC_ENFORCE(_vfs->mode() == _definition.virtualFilesMode());
515515

516-
const auto result = Vfs::checkAvailability(path(), _vfs->mode());
517-
if (!result) {
518-
_syncResult.appendErrorString(result.error());
516+
// todo: DC-219 check to see if this sync error makes it to the gui or not. We need to more clearly inform the user that they should
517+
// create a new sync connection to the remote folder, and use improved checks in the folder wizard to make sure vfs is supported
518+
// on the chosen path.
519+
// ideally we want a check like this before we even get here, eg in the area of load folder from config - but need to be sure there is
520+
// a place to clearly instruct the user that the folder sync needs to be re-built with a valid local path
521+
QString result = Vfs::pathSupportDetail(path(), _vfs->mode());
522+
if (!result.isEmpty()) {
523+
_syncResult.appendErrorString(result);
519524
setSyncState(SyncResult::SetupError);
520525
return;
521526
}

src/gui/folderman.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,6 @@ class OWNCLOUDGUI_EXPORT FolderMan : public QObject
259259

260260
void setDirtyProxy();
261261

262-
/** Whether or not vfs is supported in the location. */
263-
bool checkVfsAvailability(const QString &path, Vfs::Mode mode = VfsPluginManager::instance().bestAvailableVfsMode()) const;
264-
265-
/** If the folder configuration is no longer supported this will return an error string */
266-
Result<void, QString> unsupportedConfiguration(const QString &path) const;
267-
268262
[[nodiscard]] bool isSpaceSynced(GraphApi::Space *space) const;
269263

270264
/**

src/gui/folderstatusmodel.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
212212

213213
auto getErrors = [f] {
214214
auto errors = f->syncResult().errorStrings();
215-
const Result<void, QString> notLegacyError = FolderMan::instance()->unsupportedConfiguration(f->path());
216-
if (!notLegacyError) {
217-
errors.append(notLegacyError.error());
218-
}
219215
if (f->syncResult().hasUnresolvedConflicts()) {
220216
errors.append(tr("There are unresolved conflicts."));
221217
}

src/gui/folderwizard/folderwizard.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ FolderWizardPrivate::FolderWizardPrivate(FolderWizard *q, Account *account)
102102
QString FolderWizardPrivate::initialLocalPath() const
103103
{
104104
return FolderMan::instance()->findGoodPathForNewSyncFolder(
105-
defaultSyncRoot(), _spacesPage->currentSpace()->displayName(), FolderMan::NewFolderType::SpacesSyncRoot, _account->uuid());
105+
defaultSyncRoot(), _spacesPage->currentSpace()->displayName(), FolderMan::NewFolderType::SpacesFolder, _account->uuid());
106106
}
107107

108108
uint32_t FolderWizardPrivate::priority() const
@@ -131,12 +131,16 @@ QString FolderWizardPrivate::displayName() const
131131

132132
bool FolderWizardPrivate::useVirtualFiles() const
133133
{
134+
// todo: see other todo's related to DC-219. Basically we should simply not allow user to pick a local path that is not supported
135+
// for vfs if vfs is generally available. "Use virtual files" should not rely on the folder path check at all, as we should
136+
// block use of unsupported paths from the start (generally via account wizard and folder wizard gui's)
134137
const auto mode = VfsPluginManager::instance().bestAvailableVfsMode();
135138
const bool useVirtualFiles = (Theme::instance()->forceVirtualFilesOption() && mode == Vfs::WindowsCfApi) || (_folderWizardSelectiveSyncPage && _folderWizardSelectiveSyncPage->useVirtualFiles());
136139
if (useVirtualFiles) {
137-
const auto availability = Vfs::checkAvailability(initialLocalPath(), mode);
138-
if (!availability) {
139-
auto msg = new QMessageBox(QMessageBox::Warning, FolderWizard::tr("Virtual files are not available for the selected folder"), availability.error(), QMessageBox::Ok, ocApp()->gui()->settingsDialog());
140+
QString vfsSupported = Vfs::pathSupportDetail(initialLocalPath(), mode);
141+
if (!vfsSupported.isEmpty()) {
142+
auto msg = new QMessageBox(QMessageBox::Warning, FolderWizard::tr("Virtual files are not available for the selected folder"), vfsSupported,
143+
QMessageBox::Ok, ocApp()->gui()->settingsDialog());
140144
msg->setAttribute(Qt::WA_DeleteOnClose);
141145
msg->open();
142146
return false;
@@ -166,8 +170,11 @@ void FolderWizard::sendResult()
166170
FolderMan::SyncConnectionDescription FolderWizard::result()
167171
{
168172
Q_D(FolderWizard);
169-
173+
// DC-219 todo:
174+
// check this local path to see if it supports vfs if vfs is in play - this check should happen before the wizard is completed,
175+
// eg validate whatever page has the user choice of local path
170176
const QString localPath = d->_folderWizardSourcePage->localPath();
177+
// leave this until we fix the weird handling in account wizard that leaves the sync root empty if selective sync is chosen
171178
if (!d->_account->hasDefaultSyncRoot()) {
172179
if (FileSystem::isChildPathOf(localPath, d->defaultSyncRoot())) {
173180
d->_account->setDefaultSyncRoot(d->defaultSyncRoot());

src/gui/folderwizard/folderwizardlocalpath.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ QString FolderWizardLocalPath::localPath() const
6363

6464
bool FolderWizardLocalPath::isComplete() const
6565
{
66+
// todo: DC-219 we need a check here to see if the chosen local folder path supports vfs, provided vfs is generally available,
67+
// and reject the path with reason it failed if it's no good. Regardless of whether the user currently wants to use vfs or not,
68+
// we should not accept local paths that *can't* support vfs if they change their mind later.
69+
// use Vfs::pathSupportDetail to get the reason vfs is not supported (path is supported if the return string is empty)
6670
auto folderType = FolderMan::NewFolderType::SpacesFolder;
6771
auto accountUuid = folderWizardPrivate()->uuid();
6872
QString errorStr = FolderMan::instance()->checkPathValidity(localPath(), folderType, accountUuid);

src/gui/newaccountwizard/advancedsettingspagecontroller.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,13 @@ bool AdvancedSettingsPageController::validateSyncRoot(const QString &rootPath)
235235
// I'm not testing the case that vfs is actually the chosen mode here as if vfs is available we should just block dirs that don't support it,
236236
// the idea being that eg if they change the mode in the page after they select the dir, or use selective sync with vfs later, at least we know the default
237237
// root they select here will not cause any issues down the road
238-
if (_vfsIsAvailable && !FolderMan::instance()->checkVfsAvailability(rootPath)) {
239-
_errorField->setText(errorMessageTemplate.arg(rootPath, tr("selected path does not support using virtual file system.")));
240-
return false;
238+
// todo: use this same approach when fixing the folder wizard as part of DC-219
239+
if (_vfsIsAvailable) {
240+
QString pathSupported = Vfs::pathSupportDetail(rootPath, Vfs::Mode::WindowsCfApi);
241+
if (!pathSupported.isEmpty()) {
242+
_errorField->setText(errorMessageTemplate.arg(rootPath, tr("selected path does not support using virtual file system. %1").arg(pathSupported)));
243+
return false;
244+
}
241245
}
242246

243247
return true;

0 commit comments

Comments
 (0)