Skip to content

Commit

Permalink
Change variable tempDirectory to tempLogArchiveDir
Browse files Browse the repository at this point in the history
  • Loading branch information
herve-er committed May 8, 2024
1 parent c147e5d commit bc206e5
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/server/logarchiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ ExitCode LogArchiver::generateLogsSupportArchive(bool includeArchivedLogs, const
ExitCause& exitCause, std::function<void(int)> progressCallback) {
// Get the log directory path
const SyncPath logPath = Log::instance()->getLogFilePath().parent_path();
const SyncPath tempDirectory =
logPath / "send_log_directory_temp" / ("tempLogArchive_" + CommonUtility::generateRandomStringAlphaNum(10));
const SyncPath tempLogArchiveDir =
logPath / "temp_support_archive_generator" / ("tempLogArchive_" + CommonUtility::generateRandomStringAlphaNum(10));
exitCause = ExitCauseUnknown;
IoError ioError = IoErrorSuccess;

// Create temp folder
if (!IoHelper::createDirectory(tempDirectory.parent_path(), ioError) && ioError != IoErrorDirectoryExists) {
LOG_WARN(Log::instance()->getLogger(),
"Error in IoHelper::createDirectory: " << Utility::formatIoError(tempDirectory.parent_path(), ioError).c_str());
if (!IoHelper::createDirectory(tempLogArchiveDir.parent_path(), ioError) && ioError != IoErrorDirectoryExists) {
LOG_WARN(Log::instance()->getLogger(), "Error in IoHelper::createDirectory: "
<< Utility::formatIoError(tempLogArchiveDir.parent_path(), ioError).c_str());
if (ioError == IoErrorDiskFull) {
exitCause = ExitCauseNotEnoughDiskSpace;
} else {
Expand All @@ -69,11 +69,11 @@ ExitCode LogArchiver::generateLogsSupportArchive(bool includeArchivedLogs, const
return ExitCodeSystemError;
}

if (!IoHelper::createDirectory(tempDirectory, ioError)) {
if (!IoHelper::createDirectory(tempLogArchiveDir, ioError)) {
LOG_WARN(Log::instance()->getLogger(),
"Error in IoHelper::createDirectory: " << Utility::formatIoError(tempDirectory, ioError).c_str());
"Error in IoHelper::createDirectory: " << Utility::formatIoError(tempLogArchiveDir, ioError).c_str());
IoError ignoreError = IoErrorSuccess;
IoHelper::deleteDirectory(tempDirectory.parent_path(), ignoreError);
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ignoreError);
if (ioError == IoErrorDiskFull) {
exitCause = ExitCauseNotEnoughDiskSpace;
} else {
Expand All @@ -82,53 +82,53 @@ ExitCode LogArchiver::generateLogsSupportArchive(bool includeArchivedLogs, const
return ExitCodeSystemError;
}

ExitCode exitCode = _copyLogsTo(tempDirectory, includeArchivedLogs, exitCause);
ExitCode exitCode = _copyLogsTo(tempLogArchiveDir, includeArchivedLogs, exitCause);
if (exitCode != ExitCodeOk) {
LOG_WARN(Log::instance()->getLogger(), "Unable to copy logs to temp folder: " << exitCause);
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);
return exitCode;
}

// Copy .parmsdb to temp folder
exitCode = _copyParmsDbTo(tempDirectory / ".parms.db", exitCause);
exitCode = _copyParmsDbTo(tempLogArchiveDir / ".parms.db", exitCause);
if (exitCode != ExitCodeOk) {
LOG_WARN(Log::instance()->getLogger(), "Unable to copy .parms.db to temp folder: " << exitCause);
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);
return exitCode;
}

// Generate user description file
exitCode = _generateUserDescriptionFile(tempDirectory, exitCause);
exitCode = _generateUserDescriptionFile(tempLogArchiveDir, exitCause);
if (exitCode != ExitCodeOk) {
LOG_WARN(Log::instance()->getLogger(), "Unable to generate user description file: " << exitCause);
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);
return exitCode;
}

// compress all the files in the folder
exitCode = _compressLogFiles(tempDirectory, exitCause, progressCallback);
exitCode = _compressLogFiles(tempLogArchiveDir, exitCause, progressCallback);
if (exitCode != ExitCodeOk) {
LOG_WARN(Log::instance()->getLogger(), "Unable to compress logs: " << exitCause);
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);
return exitCode;
}

// Generate the archive
int err = 0;
zip_t* archive = zip_open((tempDirectory / archiveName).string().c_str(), ZIP_CREATE | ZIP_EXCL, &err);
zip_t* archive = zip_open((tempLogArchiveDir / archiveName).string().c_str(), ZIP_CREATE | ZIP_EXCL, &err);
if (err != ZIP_ER_OK) {
LOG_WARN(Log::instance()->getLogger(), "Error in zip_open: " << zip_strerror(archive));
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);

exitCause = ExitCauseUnknown;
return ExitCodeUnknown;
}

IoHelper::DirectoryIterator dir;
if (!IoHelper::getDirectoryIterator(tempDirectory, false, ioError, dir)) {
if (!IoHelper::getDirectoryIterator(tempLogArchiveDir, false, ioError, dir)) {
LOG_WARN(Log::instance()->getLogger(),
"Error in DirectoryIterator: " << Utility::formatIoError(tempDirectory, ioError).c_str());
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
"Error in DirectoryIterator: " << Utility::formatIoError(tempLogArchiveDir, ioError).c_str());
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);

exitCause = ExitCauseUnknown;
return ExitCodeUnknown;
Expand All @@ -144,7 +144,7 @@ ExitCode LogArchiver::generateLogsSupportArchive(bool includeArchivedLogs, const
zip_source_t* source = zip_source_file(archive, entryPath.c_str(), 0, ZIP_LENGTH_TO_END);
if (source == nullptr) {
LOG_WARN(Log::instance()->getLogger(), "Error in zip_source_file: " << zip_strerror(archive));
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);

exitCause = ExitCauseUnknown;
return ExitCodeUnknown;
Expand All @@ -153,7 +153,7 @@ ExitCode LogArchiver::generateLogsSupportArchive(bool includeArchivedLogs, const
const 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(tempDirectory.parent_path(), ioError);
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);

exitCause = ExitCauseUnknown;
return ExitCodeUnknown;
Expand All @@ -162,8 +162,8 @@ ExitCode LogArchiver::generateLogsSupportArchive(bool includeArchivedLogs, const

if (!endOfDirectory) {
LOG_WARN(Log::instance()->getLogger(),
"Error in DirectoryIterator: " << Utility::formatIoError(tempDirectory, ioError).c_str());
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
"Error in DirectoryIterator: " << Utility::formatIoError(tempLogArchiveDir, ioError).c_str());
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);

exitCause = ExitCauseUnknown;
return ExitCodeUnknown;
Expand All @@ -172,27 +172,27 @@ ExitCode LogArchiver::generateLogsSupportArchive(bool includeArchivedLogs, const
// Close the archive
if (zip_close(archive) < 0) {
LOG_WARN(Log::instance()->getLogger(), "Error in zip_close: " << zip_strerror(archive));
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);

exitCause = ExitCauseUnknown;
return ExitCodeUnknown;
}

// Copy the archive to the output path
if (!IoHelper::copyFileOrDirectory(tempDirectory / archiveName, outputPath / archiveName, ioError)) {
if (!IoHelper::copyFileOrDirectory(tempLogArchiveDir / archiveName, outputPath / archiveName, ioError)) {
LOG_WARN(Log::instance()->getLogger(),
"Error in IoHelper::copyFileOrDirectory : "
<< Utility::formatIoError(tempDirectory/ archiveName, ioError).c_str());
IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError);
<< Utility::formatIoError(tempLogArchiveDir / archiveName, ioError).c_str());
IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError);

exitCause = ExitCauseUnknown;
return ExitCodeUnknown;
}

// Delete the temp folder
if (!IoHelper::deleteDirectory(tempDirectory.parent_path(), ioError)) {
LOG_WARN(Log::instance()->getLogger(),
"Error in IoHelper::deleteDirectory: " << Utility::formatIoError(tempDirectory.parent_path(), ioError).c_str());
if (!IoHelper::deleteDirectory(tempLogArchiveDir.parent_path(), ioError)) {
LOG_WARN(Log::instance()->getLogger(), "Error in IoHelper::deleteDirectory: "
<< Utility::formatIoError(tempLogArchiveDir.parent_path(), ioError).c_str());
}

exitCause = ExitCauseUnknown;
Expand Down

0 comments on commit bc206e5

Please sign in to comment.