Skip to content

Commit

Permalink
Remove not needed exitCause = ExitCauseUnknown and move some std::str…
Browse files Browse the repository at this point in the history
…ing definition.
  • Loading branch information
herve-er committed May 7, 2024
1 parent 23dfbfd commit 3d3a751
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions src/libcommonserver/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ ExitCode Log::copyParmsDbTo(const SyncPath &outputPath, ExitCause &exitCause) {
"Error in IoHelper::getDirectoryEntry: " << Utility::formatIoError(parmsDbPath, ioError).c_str());
if (ioError == IoErrorNoSuchFileOrDirectory) {
exitCause = ExitCauseFileAccessError;
} else {
exitCause = ExitCauseUnknown;
}
return ExitCodeSystemError;
}
Expand All @@ -304,24 +302,21 @@ ExitCode Log::copyParmsDbTo(const SyncPath &outputPath, ExitCause &exitCause) {

if (ioError == IoErrorDiskFull) {
exitCause = ExitCauseNotEnoughDiskSpace;
} else {
exitCause = ExitCauseUnknown;
}
return ExitCodeSystemError;
}
exitCause = ExitCauseUnknown;
return ExitCodeOk;
}

ExitCode Log::copyLogsTo(const SyncPath &outputPath, bool includeOldLogs, ExitCause &exitCause) {
SyncPath logPath = _filePath.parent_path();
IoError ioError = IoErrorUnknown;
IoHelper::DirectoryIterator dir;
exitCause = ExitCauseUnknown;

if (!IoHelper::getDirectoryIterator(logPath, false, ioError, dir)) {
LOG_WARN(Log::instance()->getLogger(),
"Error in DirectoryIterator: " << Utility::formatIoError(logPath, ioError).c_str());
exitCause = ExitCauseUnknown;
return ExitCodeSystemError;
}

Expand All @@ -343,37 +338,33 @@ ExitCode Log::copyLogsTo(const SyncPath &outputPath, bool includeOldLogs, ExitCa
"Error in IoHelper::copyFileOrDirectory: " << Utility::formatIoError(entry.path(), ioError).c_str());
if (ioError == IoErrorDiskFull) {
exitCause = ExitCauseNotEnoughDiskSpace;
return ExitCodeSystemError;
} else {
exitCause = ExitCauseUnknown;
return ExitCodeSystemError;
}
return ExitCodeSystemError;
}
}

if (!endOfDirectory) {
LOG_WARN(Log::instance()->getLogger(),
"Error in DirectoryIterator: " << Utility::formatIoError(logPath, ioError).c_str());
exitCause = ExitCauseUnknown;
return ExitCodeSystemError;
}

exitCause = ExitCauseUnknown;
return ExitCodeOk;
}

ExitCode Log::compressLogFiles(const SyncPath &directoryToCompress, ExitCause &exitCause,
std::function<void(int)> progressCallback) {
IoHelper::DirectoryIterator dir;
IoError ioError = IoErrorUnknown;
exitCause = ExitCauseUnknown;

if (!IoHelper::getDirectoryIterator(directoryToCompress, true, ioError, dir)) {
LOG_WARN(Log::instance()->getLogger(),
"Error in DirectoryIterator: " << Utility::formatIoError(directoryToCompress, ioError).c_str());
exitCause = ExitCauseUnknown;
return ExitCodeSystemError;
}

const bool progressMonitoring = progressCallback != nullptr;
const bool progressMonitoring = progressCallback != nullptr;
float nbFiles = 0;
DirectoryEntry entry;

Expand All @@ -386,15 +377,14 @@ ExitCode Log::compressLogFiles(const SyncPath &directoryToCompress, ExitCause &e
if (!IoHelper::getDirectoryIterator(directoryToCompress, true, ioError, dir)) {
LOG_WARN(Log::instance()->getLogger(),
"Error in DirectoryIterator: " << Utility::formatIoError(directoryToCompress, ioError).c_str());
exitCause = ExitCauseUnknown;
return ExitCodeSystemError;
}
}

float progress = 0.0;
bool endOfDirectory = false;
while (dir.next(entry, endOfDirectory, ioError) && !endOfDirectory) {
const std::string entryPath = entry.path().string();
const std::string entryPath = entry.path().string();
if (entryPath.find(".gz") != std::string::npos) {
continue;
}
Expand All @@ -403,7 +393,6 @@ ExitCode Log::compressLogFiles(const SyncPath &directoryToCompress, ExitCause &e
const bool success = IoHelper::getItemType(entryPath, itemType);
ioError = itemType.ioError;
if (!success) {
exitCause = ExitCauseUnknown;
return ExitCodeSystemError;
}

Expand All @@ -416,14 +405,12 @@ ExitCode Log::compressLogFiles(const SyncPath &directoryToCompress, ExitCause &e
LOG_WARN(Log::instance()->getLogger(),
"Error in compressFile for " << entryPath.c_str() << " to " << destPath.toStdString().c_str());

exitCause = ExitCauseUnknown;
return ExitCodeSystemError;
}

if (!IoHelper::deleteDirectory(entry.path(), ioError)) { // Delete the original file
LOG_WARN(Log::instance()->getLogger(),
"Error in IoHelper::deleteDirectory: " << Utility::formatIoError(entry.path(), ioError).c_str());
exitCause = ExitCauseUnknown;
return ExitCodeSystemError;
}
if (progressMonitoring) {
Expand All @@ -436,22 +423,18 @@ ExitCode Log::compressLogFiles(const SyncPath &directoryToCompress, ExitCause &e
if (!endOfDirectory) {
LOG_WARN(Log::instance()->getLogger(),
"Error in DirectoryIterator: " << Utility::formatIoError(directoryToCompress, ioError).c_str());
exitCause = ExitCauseUnknown;
return ExitCodeSystemError;
}

return ExitCodeOk;
}

ExitCode Log::generateUserDescriptionFile(const SyncPath &outputPath, ExitCause &exitCause) {
std::string osName;
std::string osArch;
std::string appVersion;
std::string userId;

osName = CommonUtility::platformName().toStdString();
osArch = CommonUtility::platformArch().toStdString();
appVersion = CommonUtility::userAgentString();
exitCause = ExitCauseUnknown;

std::string osName = CommonUtility::platformName().toStdString();
std::string osArch = CommonUtility::platformArch().toStdString();
std::string appVersion = CommonUtility::userAgentString();

IoError ioError = IoErrorUnknown;
std::ofstream file(outputPath.string());
Expand Down

0 comments on commit 3d3a751

Please sign in to comment.