Skip to content

Commit

Permalink
Add display of the path to the generated archive in case the upload s…
Browse files Browse the repository at this point in the history
…tep failed.
  • Loading branch information
herve-er committed Apr 19, 2024
1 parent 16334af commit 81dad7f
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 61 deletions.
14 changes: 12 additions & 2 deletions src/gui/appclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
5 changes: 3 additions & 2 deletions src/gui/appclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/clientgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/gui/clientgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class ClientGui : public QObject, public std::enable_shared_from_this<ClientGui>
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:
Expand Down
37 changes: 23 additions & 14 deletions src/gui/debuggingdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}

Expand All @@ -319,34 +320,42 @@ 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"));
break;
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
3 changes: 2 additions & 1 deletion src/gui/debuggingdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/libcommon/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/libcommon/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() << ")";
Expand Down
1 change: 1 addition & 0 deletions src/libcommon/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
94 changes: 85 additions & 9 deletions src/libcommonserver/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -245,13 +263,17 @@ 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;
}

std::string entryName = entry.path().filename().string();
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;
}
}
Expand All @@ -261,13 +283,17 @@ 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;
}

// Close the archive
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;
}

Expand All @@ -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;
}

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

Expand All @@ -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;
}

Expand Down Expand Up @@ -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<User> 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<Drive> 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
Loading

0 comments on commit 81dad7f

Please sign in to comment.