diff --git a/src/server/appserver.cpp b/src/server/appserver.cpp index eeb995b46..c3e7c4e43 100644 --- a/src/server/appserver.cpp +++ b/src/server/appserver.cpp @@ -1105,10 +1105,11 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray ¶ return; } - tryCreateAndStartVfs(sync); + exitCode = tryCreateAndStartVfs(sync); + const bool start = exitCode == ExitCode::Ok; // Create and start SyncPal - exitCode = initSyncPal(sync, blackList, QSet(), whiteList, true, false, true); + exitCode = initSyncPal(sync, blackList, QSet(), whiteList, start, false, true); if (exitCode != ExitCode::Ok) { LOG_WARN(_logger, "Error in initSyncPal for syncDbId=" << syncInfo.dbId() << " code=" << exitCode); addError(Error(errId(), exitCode, exitCause)); @@ -1193,10 +1194,11 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray ¶ return; } - tryCreateAndStartVfs(sync); + exitCode = tryCreateAndStartVfs(sync); + const bool start = exitCode == ExitCode::Ok; // Create and start SyncPal - exitCode = initSyncPal(sync, blackList, QSet(), whiteList, true, false, true); + exitCode = initSyncPal(sync, blackList, QSet(), whiteList, start, false, true); if (exitCode != ExitCode::Ok) { LOG_WARN(_logger, "Error in initSyncPal for syncDbId=" << sync.dbId() << " code=" << exitCode); addError(Error(errId(), exitCode, exitCause)); @@ -2787,17 +2789,6 @@ ExitCode AppServer::tryCreateAndStartVfs(Sync &sync) noexcept { if (exitCode != ExitCode::Ok) { LOG_WARN(_logger, "Error in createAndStartVfs for syncDbId=" << sync.dbId() << " code=" << exitCode << ", pausing."); addError(Error(sync.dbId(), errId(), exitCode, exitCause)); - - // Set sync's paused flag - sync.setPaused(true); - - bool found = false; - if (!ParmsDb::instance()->setSyncPaused(sync.dbId(), true, found)) { - LOG_WARN(_logger, "Error in ParmsDb::setSyncPaused"); - } - if (!found) { - LOG_WARN(_logger, "Sync not found"); - } } return exitCode; @@ -2883,11 +2874,11 @@ ExitCode AppServer::startSyncs(User &user, ExitCause &exitCause) { continue; } - tryCreateAndStartVfs(sync); + exitCode = tryCreateAndStartVfs(sync); + const bool start = exitCode == ExitCode::Ok && !user.keychainKey().empty(); // Create and start SyncPal - exitCode = - initSyncPal(sync, blackList, undecidedList, QSet(), !user.keychainKey().empty(), false, false); + exitCode = initSyncPal(sync, blackList, undecidedList, QSet(), start, false, false); if (exitCode != ExitCode::Ok) { LOG_WARN(_logger, "Error in initSyncPal for syncDbId=" << sync.dbId() << " code=" << exitCode); addError(Error(sync.dbId(), errId(), exitCode, ExitCause::Unknown)); @@ -3862,11 +3853,10 @@ ExitCode AppServer::setSupportsVirtualFiles(int syncDbId, bool value) { // Delete previous vfs _vfsMap.erase(syncDbId); - tryCreateAndStartVfs(sync); + exitCode = tryCreateAndStartVfs(sync); + const bool start = exitCode == ExitCode::Ok; QTimer::singleShot(100, this, [=]() { - bool ok = true; - if (newMode != VirtualFileMode::Off) { // Clear file system _vfsMap[sync.dbId()]->convertDirContentToPlaceholder(SyncName2QStr(sync.localPath()), true); @@ -3880,8 +3870,8 @@ ExitCode AppServer::setSupportsVirtualFiles(int syncDbId, bool value) { // Notify conversion completed sendVfsConversionCompleted(sync.dbId()); - if (ok) { - // Re-start sync + // Re-start sync + if (start) { _syncPalMap[syncDbId]->start(); } }); diff --git a/src/server/appserver.h b/src/server/appserver.h index 313c6277e..75efe9561 100644 --- a/src/server/appserver.h +++ b/src/server/appserver.h @@ -143,7 +143,7 @@ class AppServer : public SharedTools::QtSingleApplication { ExitCode createAndStartVfs(const Sync &sync, ExitCause &exitCause) noexcept; // Call createAndStartVfs. Issue warnings, errors and pause the synchronization `sync` if needed. - ExitCode tryCreateAndStartVfs(Sync &sync) noexcept; + [[nodiscard]] ExitCode tryCreateAndStartVfs(Sync &sync) noexcept; ExitCode stopVfs(int syncDbId, bool unregister); ExitCode setSupportsVirtualFiles(int syncDbId, bool value);