Skip to content

Commit

Permalink
Manage tryCreateAndStartVfs return code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopheLarchier committed Nov 26, 2024
1 parent 0cd63de commit 9ab4adb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
36 changes: 13 additions & 23 deletions src/server/appserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,10 +1105,11 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray &para
return;
}

tryCreateAndStartVfs(sync);
exitCode = tryCreateAndStartVfs(sync);
const bool start = exitCode == ExitCode::Ok;

// Create and start SyncPal
exitCode = initSyncPal(sync, blackList, QSet<QString>(), whiteList, true, false, true);
exitCode = initSyncPal(sync, blackList, QSet<QString>(), 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));
Expand Down Expand Up @@ -1193,10 +1194,11 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray &para
return;
}

tryCreateAndStartVfs(sync);
exitCode = tryCreateAndStartVfs(sync);
const bool start = exitCode == ExitCode::Ok;

// Create and start SyncPal
exitCode = initSyncPal(sync, blackList, QSet<QString>(), whiteList, true, false, true);
exitCode = initSyncPal(sync, blackList, QSet<QString>(), 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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<QString>(), !user.keychainKey().empty(), false, false);
exitCode = initSyncPal(sync, blackList, undecidedList, QSet<QString>(), 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));
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/server/appserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9ab4adb

Please sign in to comment.