Updated to use errno instead of error_code in lg2
Since the std::error_code parameter is used in the std::filesystem
library to capture exception errors, but for some methods (such as
exists), if the file does not exist, the error_code is still 0,
because it is explained in cppreference:
```
Sets a std::error_code& parameter to the OS API error code if an OS
API call fails, and executes ec.clear() if no errors occur.
```
So the log printed as "Failed to find xxx file: success", This isn't
very clear about this log description, why the file is not found, and
then success is printed. So before printing the ec, we should first
check if it is non-zero.
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I2829a5d3c22b14b8e03077f62869fb2195b19680
diff --git a/image_verify.cpp b/image_verify.cpp
index bfdab62..b5805f5 100644
--- a/image_verify.cpp
+++ b/image_verify.cpp
@@ -305,8 +305,11 @@
std::error_code ec;
if (!(fs::exists(file, ec) && fs::exists(sigFile, ec)))
{
- error("Failed to find the Data or signature file {PATH}: {ERROR_MSG}",
- "PATH", file, "ERROR_MSG", ec.message());
+ error("Failed to find the Data or signature file {PATH}", "PATH", file);
+ if (ec)
+ {
+ error("Error message: {ERROR_MSG}", "ERROR_MSG", ec.message());
+ }
elog<InternalFailure>();
}