From cce2a3b3cd332cbbb59f37106f9b79a9a9c69e1a Mon Sep 17 00:00:00 2001 From: Luc Guyot Date: Thu, 2 May 2024 17:29:14 +0200 Subject: [PATCH] [KDESKTOP-795] Restores proper deletion of a drive with no synchronizations --- src/server/appserver.cpp | 47 ++++++++++++++++------------------------ src/server/appserver.h | 3 ++- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/server/appserver.cpp b/src/server/appserver.cpp index 979a68168..819619a77 100644 --- a/src/server/appserver.cpp +++ b/src/server/appserver.cpp @@ -375,22 +375,35 @@ void AppServer::stopAllSyncsTask(const std::vector &syncDbIdList) { } } -void AppServer::deleteAccount(int accountDbId) { +void AppServer::deleteAccountIfNeeded(int accountDbId) { std::vector driveList; if (!ParmsDb::instance()->selectAllDrives(accountDbId, driveList)) { LOG_WARN(_logger, "Error in ParmsDb::selectAllDrives"); addError(Error(ERRID, ExitCodeDbError, ExitCauseUnknown)); } else if (driveList.empty()) { - ExitCode exitCode = ServerRequests::deleteAccount(accountDbId); + const ExitCode exitCode = ServerRequests::deleteAccount(accountDbId); if (exitCode == ExitCodeOk) { sendAccountRemoved(accountDbId); } else { - LOG_WARN(_logger, "Error in Requests::deleteAccount : " << exitCode); + LOG_WARN(_logger, "Error in ServerRequests::deleteAccount: " << exitCode); addError(Error(ERRID, exitCode, ExitCauseUnknown)); } } } +void AppServer::deleteDrive(int driveDbId, int accountDbId) { + const ExitCode exitCode = ServerRequests::deleteDrive(driveDbId); + if (exitCode == ExitCodeOk) { + sendDriveRemoved(driveDbId); + } else { + LOG_WARN(_logger, "Error in Requests::deleteDrive : " << exitCode); + addError(Error(ERRID, exitCode, ExitCauseUnknown)); + sendDriveDeletionFailed(driveDbId); + } + + deleteAccountIfNeeded(accountDbId); +} + void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray ¶ms) { QByteArray results = QByteArray(); QDataStream resultStream(&results, QIODevice::WriteOnly); @@ -469,17 +482,12 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray ¶ } } - if (syncDbIdList.empty()) { - // The user has no synchronizations. - break; - } - // Stop syncs for this user and remove them from syncPalMap. QTimer::singleShot(100, [this, userDbId, syncDbIdList]() { AppServer::stopAllSyncsTask(syncDbIdList); // Delete user from DB - ExitCode exitCode = ServerRequests::deleteUser(userDbId); + const ExitCode exitCode = ServerRequests::deleteUser(userDbId); if (exitCode == ExitCodeOk) { sendUserRemoved(userDbId); } else { @@ -774,26 +782,10 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray ¶ } } - if (syncDbIdList.empty()) { - // The drive's user has no synchronizations. - break; - } - // Stop syncs for this drive and remove them from syncPalMap QTimer::singleShot(100, [this, driveDbId, accountDbId, syncDbIdList]() { AppServer::stopAllSyncsTask(syncDbIdList); - - // Delete drive from DB - const ExitCode exitCode = ServerRequests::deleteDrive(driveDbId); - if (exitCode == ExitCodeOk) { - sendDriveRemoved(driveDbId); - } else { - LOG_WARN(_logger, "Error in Requests::deleteDrive : " << exitCode); - addError(Error(ERRID, exitCode, ExitCauseUnknown)); - sendDriveDeletionFailed(driveDbId); - } - - deleteAccount(accountDbId); + AppServer::deleteDrive(driveDbId, accountDbId); }); break; @@ -3754,8 +3746,7 @@ void AppServer::sendDriveDeletionFailed(int driveDbId) { int id = 0; const auto params = QByteArray(ArgsReader(driveDbId)); - CommServer::instance() - ->sendSignal(SIGNAL_NUM_DRIVE_DELETE_FAILED, params, id); + CommServer::instance()->sendSignal(SIGNAL_NUM_DRIVE_DELETE_FAILED, params, id); } diff --git a/src/server/appserver.h b/src/server/appserver.h index 3608af82c..6c41c7b05 100644 --- a/src/server/appserver.h +++ b/src/server/appserver.h @@ -192,7 +192,8 @@ class AppServer : public SharedTools::QtSingleApplication { void startSyncPals(); void stopSyncTask(int syncDbId); // Long task which can block GUI: post-poned in the event loop by means of timer void stopAllSyncsTask(const std::vector &syncDbIdList); // Idem. - void deleteAccount(int accountDbId); + void deleteAccountIfNeeded(int accountDbId); // Remove the account if no drive is associated to it. + void deleteDrive(int driveDbId, int accountDbId); static void addError(const Error &error); static void sendErrorAdded(bool serverLevel, ExitCode exitCode, int syncDbId);