From 81dad7f863bba6969c0dcb4d89f9687ef4ea0006 Mon Sep 17 00:00:00 2001 From: Herve_eruam Date: Fri, 19 Apr 2024 11:32:23 +0200 Subject: [PATCH] Add display of the path to the generated archive in case the upload step failed. --- src/gui/appclient.cpp | 14 ++- src/gui/appclient.h | 5 +- src/gui/clientgui.cpp | 4 +- src/gui/clientgui.h | 3 +- src/gui/debuggingdialog.cpp | 37 +++++--- src/gui/debuggingdialog.h | 3 +- src/libcommon/comm.h | 3 +- src/libcommon/utility/utility.cpp | 4 + src/libcommon/utility/utility.h | 1 + src/libcommonserver/log/log.cpp | 94 +++++++++++++++++-- src/libcommonserver/log/log.h | 25 ++--- src/libsyncengine/requests/serverrequests.cpp | 22 +++-- src/libsyncengine/requests/serverrequests.h | 2 +- src/server/appserver.cpp | 24 ++++- src/server/appserver.h | 5 +- 15 files changed, 185 insertions(+), 61 deletions(-) diff --git a/src/gui/appclient.cpp b/src/gui/appclient.cpp index 13bc595de..bc69fbfe7 100644 --- a/src/gui/appclient.cpp +++ b/src/gui/appclient.cpp @@ -456,13 +456,23 @@ void AppClient::onSignalReceived(int id, /*SignalNum*/ int num, const QByteArray emit showSynthesisDialog(); break; } - case SIGNAL_NUM_UTILITY_SEND_LOG_TO_SUPPORT_STATUS: { + case SIGNAL_NUM_UTILITY_LOG_UPLOAD_STATUS_UPDATED: { char status; int64_t progress; paramsStream >> status; paramsStream >> progress; - emit updateLogToSupportStatus(status, progress); + emit logUploadStatusUpdated(status, progress); + break; + } + case SIGNAL_NUM_UTILITY_LOG_UPLOAD_COMPLETED: { + bool success; + SyncPath archivePath; + QString archivePathStr; + paramsStream >> success; + paramsStream >> archivePathStr; + archivePath = SyncPath(archivePathStr.toStdString()); + emit logUploadCompleted(success, archivePath); break; } default: { diff --git a/src/gui/appclient.h b/src/gui/appclient.h index e87b207cb..32ee8f02a 100644 --- a/src/gui/appclient.h +++ b/src/gui/appclient.h @@ -94,9 +94,10 @@ class AppClient : public SharedTools::QtSingleApplication { void showNotification(const QString &title, const QString &message); void errorAdded(bool serverLevel, ExitCode exitCode, int syncDbId); void errorsCleared(int syncDbId); - void updateLogToSupportStatus( - const char state /*state: 'A' for Archiving, 'U' for uploading, 'F' for failed, 'S' for Succes*/, + void logUploadStatusUpdated( + const char state /*state: 'A' for Archiving, 'U' for uploading*/, const int64_t percent); + void logUploadCompleted(bool success, const SyncPath &archivePath); public slots: void onWizardDone(int); diff --git a/src/gui/clientgui.cpp b/src/gui/clientgui.cpp index 8930d604d..4f2971ac4 100644 --- a/src/gui/clientgui.cpp +++ b/src/gui/clientgui.cpp @@ -103,8 +103,8 @@ ClientGui::ClientGui(AppClient *parent) connect(_app, &AppClient::errorsCleared, this, &ClientGui::onErrorsCleared); connect(_app, &AppClient::folderSizeCompleted, this, &ClientGui::folderSizeCompleted); connect(_app, &AppClient::fixConflictingFilesCompleted, this, &ClientGui::onFixConflictingFilesCompleted); - - connect(_app, &AppClient::updateLogToSupportStatus, this, &ClientGui::logToSupportStatusUpdated); + connect(_app, &AppClient::logUploadStatusUpdated, this, &ClientGui::logUploadStatusUpdated); + connect(_app, &AppClient::logUploadCompleted, this, &ClientGui::logUploadCompleted); connect(this, &ClientGui::refreshStatusNeeded, this, &ClientGui::onRefreshStatusNeeded); diff --git a/src/gui/clientgui.h b/src/gui/clientgui.h index cd076e807..fb7fd3ce3 100644 --- a/src/gui/clientgui.h +++ b/src/gui/clientgui.h @@ -102,7 +102,8 @@ class ClientGui : public QObject, public std::enable_shared_from_this void refreshStatusNeeded(); void folderSizeCompleted(QString nodeId, qint64 size); void driveBeingRemoved(); - void logToSupportStatusUpdated(char status, int64_t progress); + void logUploadStatusUpdated(char status, int64_t progress); + void logUploadCompleted(bool success, const SyncPath &archivePath); public slots: diff --git a/src/gui/debuggingdialog.cpp b/src/gui/debuggingdialog.cpp index bbb4aafe4..c443fff83 100644 --- a/src/gui/debuggingdialog.cpp +++ b/src/gui/debuggingdialog.cpp @@ -208,7 +208,8 @@ void DebuggingDialog::initUI() { connect(_sendLogButton, &QPushButton::clicked, this, &DebuggingDialog::onSendLogButtonTriggered); connect(cancelButton, &QPushButton::clicked, this, &DebuggingDialog::onExit); connect(this, &CustomDialog::exit, this, &DebuggingDialog::onExit); - connect(_gui.get(), &ClientGui::logToSupportStatusUpdated, this, &DebuggingDialog::onSendLogProgressUpdate); + connect(_gui.get(), &ClientGui::logUploadStatusUpdated, this, &DebuggingDialog::onLogUploadStatusUpdated); + connect(_gui.get(), &ClientGui::logUploadCompleted, this, &DebuggingDialog::onLogUploadCompleted); } void DebuggingDialog::updateUI() { @@ -293,7 +294,7 @@ void DebuggingDialog::onSendLogButtonTriggered() { int64_t size; ExitCode exitCode = GuiRequests::getAproximateLogSize(size); if (exitCode != ExitCode::ExitCodeOk) { - onSendLogConfirmed(true); // Send all logs by default if we can't get the aproximate size + onSendLogConfirmed(true); // Send all logs by default if we can't get the aproximate size return; } @@ -319,13 +320,17 @@ void DebuggingDialog::onSendLogConfirmed(bool allLog) { ExitCode exitCode = GuiRequests::sendLogToSupport(allLog); if (exitCode != ExitCode::ExitCodeOk) { - onSendLogProgressUpdate('F', 0); + onLogUploadStatusUpdated('F', 0); } } -void DebuggingDialog::onSendLogProgressUpdate(char status, int64_t progress) { +void DebuggingDialog::onLogUploadStatusUpdated(char status, int64_t progress) { int progressValue = progress; + _sendLogButton->setEnabled(false); + _sendLogProgressBar->show(); + _sendLogStatusLabel->show(); _sendLogProgressBar->setValue(progressValue); + switch (status) { case 'A': _sendLogStatusLabel->setText(tr("1/2 | Compression")); @@ -333,20 +338,24 @@ void DebuggingDialog::onSendLogProgressUpdate(char status, int64_t progress) { case 'U': _sendLogStatusLabel->setText(tr("2/2 | Upload")); break; - case 'S': - _sendLogStatusLabel->setText(tr("Log sent to Infomaniak support.")); - _sendLogProgressBar->hide(); - _sendLogButton->setEnabled(true); - break; - case 'F': - _sendLogStatusLabel->setText(tr("Failed")); - _sendLogProgressBar->hide(); - _sendLogButton->setEnabled(true); - break; default: _sendLogStatusLabel->setText(tr("Sending logs...")); break; } } +void DebuggingDialog::onLogUploadCompleted(bool success, const SyncPath &archivePath) { + if (success) { + _sendLogStatusLabel->setText(tr("Log sent to Infomaniak support.")); + _sendLogProgressBar->hide(); + _sendLogButton->setEnabled(true); + } else { + _sendLogStatusLabel->setText( + tr("Failed to send logs to Infomaniak support. You can manually send the file available at %1") + .arg(QString::fromStdString(archivePath.string()))); + _sendLogProgressBar->hide(); + _sendLogButton->setEnabled(true); + } +} + } // namespace KDC diff --git a/src/gui/debuggingdialog.h b/src/gui/debuggingdialog.h index 87d941357..100a0216b 100644 --- a/src/gui/debuggingdialog.h +++ b/src/gui/debuggingdialog.h @@ -71,7 +71,8 @@ class DebuggingDialog : public CustomDialog { void onSaveButtonTriggered(bool checked = false); void onSendLogButtonTriggered(); void onSendLogConfirmed(bool allLog); - void onSendLogProgressUpdate(char status, int64_t progress); + void onLogUploadStatusUpdated(char status, int64_t progress); + void onLogUploadCompleted(bool success, const SyncPath &archivePath); }; } // namespace KDC diff --git a/src/libcommon/comm.h b/src/libcommon/comm.h index 8a9123bc7..7a9f92e6b 100644 --- a/src/libcommon/comm.h +++ b/src/libcommon/comm.h @@ -159,7 +159,8 @@ typedef enum { SIGNAL_NUM_UTILITY_ERRORS_CLEARED, SIGNAL_NUM_UTILITY_SHOW_SETTINGS, SIGNAL_NUM_UTILITY_SHOW_SYNTHESIS, - SIGNAL_NUM_UTILITY_SEND_LOG_TO_SUPPORT_STATUS, + SIGNAL_NUM_UTILITY_LOG_UPLOAD_STATUS_UPDATED, + SIGNAL_NUM_UTILITY_LOG_UPLOAD_COMPLETED } SignalNum; struct ArgsReader { diff --git a/src/libcommon/utility/utility.cpp b/src/libcommon/utility/utility.cpp index 3c9004f37..c30902cd4 100644 --- a/src/libcommon/utility/utility.cpp +++ b/src/libcommon/utility/utility.cpp @@ -111,6 +111,10 @@ QString CommonUtility::platformName() { return QSysInfo::prettyProductName(); } +QString CommonUtility::platformArch() { + return QSysInfo::currentCpuArchitecture(); +} + std::string CommonUtility::userAgentString() { std::ostringstream userAgent; userAgent << APPLICATION_SHORTNAME << " / " << KDRIVE_VERSION_STRING << " (" << platformName().toStdString() << ")"; diff --git a/src/libcommon/utility/utility.h b/src/libcommon/utility/utility.h index 9b5d00918..6ee2eef2f 100644 --- a/src/libcommon/utility/utility.h +++ b/src/libcommon/utility/utility.h @@ -55,6 +55,7 @@ struct COMMON_EXPORT CommonUtility { static qint64 freeDiskSpace(const QString &path); static void crash(); static QString platformName(); + static QString platformArch(); static QByteArray IntToArray(qint32 source); static int ArrayToInt(QByteArray source); static QString escape(const QString &in); diff --git a/src/libcommonserver/log/log.cpp b/src/libcommonserver/log/log.cpp index c05194061..28019613f 100644 --- a/src/libcommonserver/log/log.cpp +++ b/src/libcommonserver/log/log.cpp @@ -19,6 +19,9 @@ #include "log.h" #include "customrollingfileappender.h" #include "utility/utility.h" +#include "libparms/db/user.h" +#include "libparms/db/parmsdb.h" +#include "libparms/db/drive.h" #include "libcommonserver/io/iohelper.h" #include "libcommon/utility/utility.h" @@ -163,8 +166,7 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output // Get the log directory path SyncPath logPath; ioError = IoErrorSuccess; - IoHelper::logDirectoryPath(logPath, ioError); - if (ioError != IoErrorSuccess) { + if (!IoHelper::logDirectoryPath(logPath, ioError) || ioError != IoErrorSuccess) { LOG_WARN(Log::instance()->getLogger(), "Error in IoHelper::logDirectoryPath : " << Utility::formatIoError(logPath, ioError).c_str()); return false; @@ -185,7 +187,8 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output LOG_WARN(Log::instance()->getLogger(), "Error in IoHelper::createDirectory : " << Utility::formatIoError(logPath / "send_log_directory_temp" / tempsFolderName, ioError).c_str()); - IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + IoError ignoreError; + IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ignoreError); return false; } @@ -194,18 +197,29 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output LOG_WARN(Log::instance()->getLogger(), "Error in copyLogsTo : " << Utility::formatIoError(logPath / "send_log_directory_temp" / tempsFolderName, ioError).c_str()); - IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + IoError ignoreError; + IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ignoreError); return false; } - // Copy .parmsdb to temp folder if (!copyParmsDbTo(logPath / "send_log_directory_temp" / tempsFolderName / ".parms.db", ioError)) { LOG_WARN( Log::instance()->getLogger(), "Error in copyParmsDbTo : " << Utility::formatIoError(logPath / "send_log_directory_temp" / tempsFolderName / ".parms.db", ioError).c_str()); - IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + IoError ignoreError; + IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ignoreError); + return false; + } + + // Generate user description file + if (!generateUserDescriptionFile(logPath / "send_log_directory_temp" / tempsFolderName, ioError)) { + LOG_WARN(Log::instance()->getLogger(), + "Error in generateUserDescriptionFile : " + << Utility::formatIoError(logPath / "send_log_directory_temp" / tempsFolderName, ioError).c_str()); + IoError ignoreError; + IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ignoreError); return false; } @@ -214,7 +228,8 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output LOG_WARN(Log::instance()->getLogger(), "Error in compressLogs : " << Utility::formatIoError(logPath / "send_log_directory_temp" / tempsFolderName, ioError).c_str()); - IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + IoError ignoreError; + IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ignoreError); return false; } @@ -226,6 +241,7 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output LOG_WARN(Log::instance()->getLogger(), "Error in zip_open : " << err); IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + ioError = IoErrorUnknown; return false; } @@ -236,6 +252,8 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output "Error in DirectoryIterator : " << Utility::formatIoError(logPath / "send_log_directory_temp" / tempsFolderName, ioError).c_str()); IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + ioError = IoErrorUnknown; + return false; } @@ -245,6 +263,8 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output if (source == nullptr) { LOG_WARN(Log::instance()->getLogger(), "Error in zip_source_file : " << zip_strerror(archive)); IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + ioError = IoErrorUnknown; + return false; } @@ -252,6 +272,8 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output if (zip_file_add(archive, entryName.c_str(), source, ZIP_FL_OVERWRITE) < 0) { LOG_WARN(Log::instance()->getLogger(), "Error in zip_file_add : " << zip_strerror(archive)); IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + ioError = IoErrorUnknown; + return false; } } @@ -261,6 +283,8 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output "Error in DirectoryIterator : " << Utility::formatIoError(logPath / "send_log_directory_temp" / tempsFolderName, ioError).c_str()); IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + ioError = IoErrorUnknown; + return false; } @@ -268,6 +292,8 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output if (zip_close(archive) < 0) { LOG_WARN(Log::instance()->getLogger(), "Error in zip_close : " << zip_strerror(archive)); IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + ioError = IoErrorUnknown; + return false; } @@ -277,6 +303,8 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output "Error in IoHelper::copyFileOrDirectory : " << Utility::formatIoError(logPath / "send_log_directory_temp" / archiveName, ioError).c_str()); IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); + ioError = IoErrorUnknown; + return false; } @@ -286,6 +314,8 @@ bool Log::generateLogsSupportArchive(bool includeOldLogs, const SyncPath &output "Error in IoHelper::deleteDirectory : " << Utility::formatIoError(logPath / "send_log_directory_temp", ioError).c_str()); } + ioError = IoErrorSuccess; + return true; } @@ -321,7 +351,6 @@ bool Log::copyLogsTo(const SyncPath &outputPath, bool includeOldLogs, IoError &i if (!IoHelper::getDirectoryIterator(logPath, false, ioError, dir)) { LOG_WARN(Log::instance()->getLogger(), "Error in DirectoryIterator : " << Utility::formatIoError(logPath, ioError).c_str()); - IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); return false; } @@ -346,9 +375,9 @@ bool Log::copyLogsTo(const SyncPath &outputPath, bool includeOldLogs, IoError &i if (ioError != IoErrorEndOfDirectory) { LOG_WARN(Log::instance()->getLogger(), "Error in DirectoryIterator : " << Utility::formatIoError(logPath, ioError).c_str()); - IoHelper::deleteDirectory(logPath / "send_log_directory_temp", ioError); return false; } + ioError = IoErrorSuccess; return true; } @@ -409,5 +438,52 @@ bool Log::compressLogs(const SyncPath &directoryToCompress, IoError &ioError, st return true; } +bool Log::generateUserDescriptionFile(const SyncPath &outputPath, IoError &ioError) { + SyncPath filePath = outputPath / "user_description.txt"; + + std::string osName, osArch, appVersion, userId; + // CommonUtility::getRunningOS(osName, osVersion, osArch); + osName = CommonUtility::platformName().toStdString(); + osArch = CommonUtility::platformArch().toStdString(); + appVersion = CommonUtility::userAgentString(); + + std::ofstream file(filePath.string()); + if (!file.is_open()) { + LOG_WARN(Log::instance()->getLogger(), "Error in creating file : " << Utility::formatIoError(filePath, ioError).c_str()); + ioError = IoErrorUnknown; + return false; + } + file << "OS Name: " << osName << std::endl; + file << "OS Architecture: " << osArch << std::endl; + file << "App Version: " << appVersion << std::endl; + file << "User ID(s): "; + + std::vector userList; + if (ParmsDb::instance()->selectAllUsers(userList)) { + for (const User &user : userList) { + file << user.userId() << " | "; + } + file << std::endl; + } else { + file << "Unable to retrieve user ID(s)" << std::endl; + LOG_WARN(_logger, "Error in ParmsDb::selectAllUsers"); + } + + file << "Drive ID(s): "; + std::vector driveList; + if (ParmsDb::instance()->selectAllDrives(driveList)) { + for (const Drive &drive : driveList) { + file << drive.driveId() << " | "; + } + file << std::endl; + } else { + file << "Unable to retrieve drive ID(s)" << std::endl; + LOG_WARN(_logger, "Error in ParmsDb::selectAllUsers"); + } + + file.close(); + return true; +} + } // namespace KDC diff --git a/src/libcommonserver/log/log.h b/src/libcommonserver/log/log.h index 84e50f93c..71765ef0f 100644 --- a/src/libcommonserver/log/log.h +++ b/src/libcommonserver/log/log.h @@ -162,27 +162,30 @@ class COMMONSERVER_EXPORT Log { bool configure(bool useLog, LogLevel logLevel, bool purgeOldLogs); /*! Returns the estimated size of the log files in bytes. - * Actual size may be different due to compression. - * \param ioError The error object to be filled in case of error. - * \return The estimated size of the log files in bytes. - */ + * Actual size may be different due to compression. + * \param ioError The error object to be filled in case of error. + * \return The estimated size of the log files in bytes. + */ int64_t getLogEstimatedSize(IoError &ioError); /*! Generates a support archive containing the logs and the parms.db file. - * \param includeOldLogs If true, the old logs will be included in the archive. - * \param outputPath The path where the archive will be generated. - * \param archiveName The name of the archive. - * \param ioError The error object to be filled in case of error. - * \return True if the archive was generated successfully, false otherwise. - */ + * \param includeOldLogs If true, the old logs will be included in the archive. + * \param outputPath The path where the archive will be generated. + * \param archiveName The name of the archive. + * \param ioError The error object to be filled in case of error. + * \return True if the archive was generated successfully, false otherwise. + */ bool generateLogsSupportArchive(bool includeOldLogs, const SyncPath &outputPath, const SyncPath &archiveName, IoError &ioError, std::function progressCallback = nullptr); + bool generateUserDescriptionFile(const SyncPath &outputPath, IoError &ioError); // TODO: set this method as private + private: Log(const log4cplus::tstring &filePath); bool copyLogsTo(const SyncPath &outputPath, bool includeOldLogs, IoError &ioError); bool copyParmsDbTo(const SyncPath &outputPath, IoError &ioError); - bool compressLogs(const SyncPath &directoryToCompress, IoError &ioError, std::function progressCallback = nullptr); + bool compressLogs(const SyncPath &directoryToCompress, IoError &ioError, + std::function progressCallback = nullptr); static std::shared_ptr _instance; log4cplus::Logger _logger; }; diff --git a/src/libsyncengine/requests/serverrequests.cpp b/src/libsyncengine/requests/serverrequests.cpp index f4fb24c89..6a96e50b8 100644 --- a/src/libsyncengine/requests/serverrequests.cpp +++ b/src/libsyncengine/requests/serverrequests.cpp @@ -913,9 +913,10 @@ ExitCode ServerRequests::generateLogDirectory(SyncPath &logDirectoryPath, bool s IoHelper::deleteDirectory(tempFolder, ioError); return ExitCodeSystemError; } + logDirectoryPath = tempFolder.string() + "/" + archiveName; - LOG_DEBUG(Log::instance()->getLogger(), "Log archive for support saved at: " << logDirectoryPath.c_str()); + LOG_INFO(Log::instance()->getLogger(), "Log archive for support saved at: " << logDirectoryPath.c_str()); return ExitCodeOk; } @@ -1005,32 +1006,35 @@ ExitCode ServerRequests::getUserFromSyncDbId(int syncDbId, User &user) { return ExitCodeOk; } -ExitCode ServerRequests::sendLogToSupport(bool sendAllLogs, std::function progressCallback) { +ExitCode ServerRequests::sendLogToSupport(bool sendAllLogs, SyncPath &archivePath, + std::function progressCallback) { SyncPath logArchivePath; bool progressMonitoring = progressCallback != nullptr; ExitCode exitCode = ExitCodeOk; if (progressMonitoring) { - generateLogDirectory(logArchivePath, sendAllLogs, - [progressCallback](int64_t progress) { progressCallback('A', progress); }); + exitCode = generateLogDirectory(logArchivePath, sendAllLogs, + [progressCallback](int64_t progress) { progressCallback('A', progress); }); } else { - generateLogDirectory(logArchivePath, sendAllLogs); + exitCode = generateLogDirectory(logArchivePath, sendAllLogs); } if (exitCode != ExitCodeOk) { if (progressMonitoring) { - progressCallback('F', 0); // Failed + progressCallback('A', 0); // Failed } return exitCode; } + archivePath = logArchivePath; + // Send log placeholder // TODO: Implement new API route for sending logs for (int i = 0; i < 100; i += 1) { if (progressMonitoring) { progressCallback('U', i); // Uploading + //std::this_thread::sleep_for(std::chrono::milliseconds(50)); } - std::this_thread::sleep_for(std::chrono::milliseconds(100)); } @@ -1042,9 +1046,7 @@ ExitCode ServerRequests::sendLogToSupport(bool sendAllLogs, std::functiongetLogger(), "Error in IoHelper::deleteFile : " << Utility::formatIoError(logArchivePath, ioError).c_str()); } - if (progressMonitoring) { - progressCallback('S', 100); // Success - } + return ExitCodeOk; } diff --git a/src/libsyncengine/requests/serverrequests.h b/src/libsyncengine/requests/serverrequests.h index 86c45f3d8..9e657855f 100644 --- a/src/libsyncengine/requests/serverrequests.h +++ b/src/libsyncengine/requests/serverrequests.h @@ -139,7 +139,7 @@ struct SYNCENGINE_EXPORT ServerRequests { static bool isDisplayableError(const Error &error); static bool isAutoResolvedError(const Error &error); static ExitCode getUserFromSyncDbId(int syncDbId, User &user); - static ExitCode sendLogToSupport(bool sendAllLogs, std::function progressCallback = nullptr); + static ExitCode sendLogToSupport(bool sendAllLogs, SyncPath &archivePath, std::function progressCallback = nullptr); private: static ExitCode processRequestTokenFinished(const Login &login, UserInfo &userInfo, bool &userCreated); diff --git a/src/server/appserver.cpp b/src/server/appserver.cpp index 6003a21a0..3cf85cc7b 100644 --- a/src/server/appserver.cpp +++ b/src/server/appserver.cpp @@ -345,7 +345,6 @@ AppServer::AppServer(int &argc, char **argv) // Restart paused syncs connect(&_restartSyncsTimer, &QTimer::timeout, this, &AppServer::onRestartSyncs); _restartSyncsTimer.start(RESTART_SYNCS_INTERVAL); - } AppServer::~AppServer() { @@ -671,14 +670,19 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray ¶ QTimer::singleShot(100, [this, sendAllLogs]() { std::function progressFunc = [this](char status, int64_t progress) { - sendLogTransfertStatus(status, progress); + sendLogUploadStatusUpdated(status, progress); LOG_DEBUG(_logger, "Log transfert progress : " << status << " | " << progress << " %"); }; - ExitCode exitCode = ServerRequests::sendLogToSupport(sendAllLogs, progressFunc); + + SyncPath archivePath; + ExitCode exitCode = ServerRequests::sendLogToSupport(sendAllLogs, archivePath, progressFunc); + if (exitCode != ExitCodeOk) { LOG_WARN(_logger, "Error in Requests::sendLogToSupport : " << exitCode); addError(Error(ERRID, exitCode, ExitCauseUnknown)); } + + sendLogUploadCompleted(exitCode == ExitCodeOk, archivePath); }); LOG_WARN(_logger, "Send log to support requested"); @@ -1993,14 +1997,24 @@ void AppServer::sendErrorsCleared(int syncDbId) { CommServer::instance()->sendSignal(SIGNAL_NUM_UTILITY_ERRORS_CLEARED, params, id); } -void AppServer::sendLogTransfertStatus(const char state, const int64_t percent) { +void AppServer::sendLogUploadStatusUpdated(const char state, const int64_t percent) { int id; QByteArray params; QDataStream paramsStream(¶ms, QIODevice::WriteOnly); paramsStream << state; paramsStream << percent; - CommServer::instance()->sendSignal(SIGNAL_NUM_UTILITY_SEND_LOG_TO_SUPPORT_STATUS, params, id); + CommServer::instance()->sendSignal(SIGNAL_NUM_UTILITY_LOG_UPLOAD_STATUS_UPDATED, params, id); +} + +void AppServer::sendLogUploadCompleted(bool success, const SyncPath &archivePath) { + int id; + + QByteArray params; + QDataStream paramsStream(¶ms, QIODevice::WriteOnly); + paramsStream << success; + paramsStream << QString::fromStdString(archivePath.string()); + CommServer::instance()->sendSignal(SIGNAL_NUM_UTILITY_LOG_UPLOAD_COMPLETED, params, id); } ExitCode AppServer::checkIfSyncIsValid(const Sync &sync) { diff --git a/src/server/appserver.h b/src/server/appserver.h index 582c3a0b4..fc207efb9 100644 --- a/src/server/appserver.h +++ b/src/server/appserver.h @@ -191,9 +191,10 @@ class AppServer : public SharedTools::QtSingleApplication { void sendGetFolderSizeCompleted(const QString &nodeId, qint64 size); void sendNewBigFolder(int syncDbId, const QString &path); void sendErrorsCleared(int syncDbId); - void sendLogTransfertStatus( - const char state /*state: 'A' for Archiving, 'U' for uploading, 'F' for failed, 'S' for Succes*/, + void sendLogUploadStatusUpdated( + const char state /*state: 'A' for Archiving, 'U' for uploading*/, const int64_t percent); + void sendLogUploadCompleted(bool success, const SyncPath &archivePath); 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.