clang-tidy: Enable cert-env33-c
Modified code to address issues flagged by this check.
Tested: Build and unit tests completed successfully.
Change-Id: Ic84d34ce664870988054284ecba4903805037210
Signed-off-by: Jayanth Othayoth <ojayanth@gmail.com>
diff --git a/certificate.cpp b/certificate.cpp
index 0ff3ad5..18c68a0 100644
--- a/certificate.cpp
+++ b/certificate.cpp
@@ -116,27 +116,24 @@
void Certificate::copyCertificate(const std::string& certSrcFilePath,
const std::string& certFilePath)
{
- // Copy the certificate to the installation path
- // During bootup will be parsing existing file so no need to
- // copy it.
- if (certSrcFilePath != certFilePath)
+ try
{
- // -p flag preserves the file metadata when copying
- // -f flag forces the copy
- const std::string command =
- std::format("cp -fp {} {}", certSrcFilePath, certFilePath);
- int statusCode = std::system(command.c_str());
-
- // Non-zero `status_code` indicates something went wrong with issuing
- // the copy command.
- if (statusCode != 0)
+ // Copy the certificate to the installation path
+ // During bootup will be parsing existing file so no need to
+ // copy it.
+ if (certSrcFilePath != certFilePath)
{
- lg2::error(
- "Failed to copy certificate, ERR:{ERR}, SRC:{SRC}, DST:{DST}",
- "ERR", statusCode, "SRC", certSrcFilePath, "DST", certFilePath);
- elog<InternalFailure>();
+ fs::copy(certSrcFilePath, certFilePath,
+ fs::copy_options::overwrite_existing);
}
}
+ catch (const fs::filesystem_error& e)
+ {
+ lg2::error(
+ "Failed to copy certificate, ERR:{ERR}, SRC:{SRC}, DST:{DST}",
+ "ERR", e.what(), "SRC", certSrcFilePath, "DST", certFilePath);
+ elog<InternalFailure>();
+ }
}
std::string