Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KDESKTOP-795] Restores proper deletion of a drive with no synchronizations #94

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
ClementKunz marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading