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/.clang-tidy b/.clang-tidy
index ae30b79..f333237 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -89,6 +89,7 @@
cert-dcl54-cpp,
cert-dcl58-cpp,
cert-dcl59-cpp,
+cert-env33-c,
cert-err09-cpp,
cert-err34-c,
cert-err52-cpp,
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
diff --git a/test/.clang-tidy b/test/.clang-tidy
new file mode 100644
index 0000000..40371e6
--- /dev/null
+++ b/test/.clang-tidy
@@ -0,0 +1 @@
+Checks: '-cert-env33-c'