Skip to content

Commit

Permalink
[KDESKTOP-795] Restores proper deletion of a drive with no synchroniz…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
luc-guyot-infomaniak committed May 2, 2024
1 parent 32981b7 commit cce2a3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
47 changes: 19 additions & 28 deletions src/server/appserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,22 +375,35 @@ void AppServer::stopAllSyncsTask(const std::vector<int> &syncDbIdList) {
}
}

void AppServer::deleteAccount(int accountDbId) {
void AppServer::deleteAccountIfNeeded(int accountDbId) {
std::vector<Drive> 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 &params) {
QByteArray results = QByteArray();
QDataStream resultStream(&results, QIODevice::WriteOnly);
Expand Down Expand Up @@ -469,17 +482,12 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray &para
}
}

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 {
Expand Down Expand Up @@ -774,26 +782,10 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray &para
}
}

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;
Expand Down Expand Up @@ -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);
}


Expand Down
3 changes: 2 additions & 1 deletion src/server/appserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> &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);
Expand Down

0 comments on commit cce2a3b

Please sign in to comment.