From 65b67b3ff594b5b9baa6f52108510afff1c99f7c Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Mon, 13 Sep 2021 15:01:34 +0200 Subject: Fix crash on missing sync root Fixes: #9016 --- src/gui/folder.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/gui/folder.cpp') diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 98e885056..f4c0cbaa5 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -77,7 +77,7 @@ Folder::Folder(const FolderDefinition &definition, _syncResult.setStatus(status); // check if the local path exists - checkLocalPath(); + const auto folderOk = checkLocalPath(); _syncResult.setFolder(_definition.alias); @@ -141,8 +141,10 @@ Folder::Folder(const FolderDefinition &definition, saveToSettings(); } - // Initialize the vfs plugin - startVfs(); + if (folderOk) { + // Initialize the vfs plugin + startVfs(); + } } Folder::~Folder() @@ -155,7 +157,7 @@ Folder::~Folder() _engine.reset(); } -void Folder::checkLocalPath() +bool Folder::checkLocalPath() { const QFileInfo fi(_definition.localPath); _canonicalLocalPath = fi.canonicalFilePath(); @@ -173,18 +175,22 @@ void Folder::checkLocalPath() if (fi.isDir() && fi.isReadable()) { qCDebug(lcFolder) << "Checked local path ok"; } else { + QString error; // Check directory again if (!FileSystem::fileExists(_definition.localPath, fi)) { - _syncResult.appendErrorString(tr("Local folder %1 does not exist.").arg(_definition.localPath)); - _syncResult.setStatus(SyncResult::SetupError); + error = tr("Local folder %1 does not exist.").arg(_definition.localPath); } else if (!fi.isDir()) { - _syncResult.appendErrorString(tr("%1 should be a folder but is not.").arg(_definition.localPath)); - _syncResult.setStatus(SyncResult::SetupError); + error = tr("%1 should be a folder but is not.").arg(_definition.localPath); } else if (!fi.isReadable()) { - _syncResult.appendErrorString(tr("%1 is not readable.").arg(_definition.localPath)); + error = tr("%1 is not readable.").arg(_definition.localPath); + } + if (!error.isEmpty()) { + _syncResult.appendErrorString(error); _syncResult.setStatus(SyncResult::SetupError); + return false; } } + return true; } QString Folder::shortGuiRemotePathOrAppName() const @@ -283,7 +289,7 @@ bool Folder::syncPaused() const bool Folder::canSync() const { - return !syncPaused() && accountState()->isConnected(); + return !syncPaused() && accountState()->isConnected() && _syncResult.status() != SyncResult::SetupError; } bool Folder::dueToSync() const @@ -495,6 +501,13 @@ void Folder::startVfs() OC_ENFORCE(_vfs); OC_ENFORCE(_vfs->mode() == _definition.virtualFilesMode); + const auto result = Vfs::checkAvailability(path(), _vfs->mode()); + if (!result) { + _syncResult.appendErrorString(result.error()); + _syncResult.setStatus(SyncResult::SetupError); + return; + } + VfsSetupParams vfsParams; vfsParams.filesystemPath = path(); vfsParams.remotePath = remotePathTrailingSlash(); -- cgit v1.2.3