Skip to content

Commit

Permalink
tool: Fix to not display header
Browse files Browse the repository at this point in the history
Change:
-When there is no resolved guard record to display, the header
gets displayed. So in this case displaying message
"No Records to display"

Test:
-Created, listed and deleted the guard records, able to see
the message instead of header.

Signed-off-by: Chirag Sharma <[email protected]>
  • Loading branch information
Chirag Sharma committed Jul 29, 2021
1 parent 49d7e62 commit 0dd4d16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,36 @@
using namespace std;
using namespace openpower::guard;

void printHeader(bool display)
{
if (display)
{
std::cout << "ID | ERROR | Type | Path " << std::endl;
}
else
{
std::cout << "No Records to display" << std::endl;
}
}

void guardList(bool displayResolved)
{
bool isHeaderPrinted = false;
auto records = getAll();
if (!records.size())
{
std::cout << "No Records to display" << std::endl;
return;
}
std::cout << "ID | ERROR | Type | Path " << std::endl;
for (const auto& elem : records)
{
if (displayResolved)
{
if ((elem.recordId == GUARD_RESOLVED) && !isHeaderPrinted)
{
printHeader(true);
isHeaderPrinted = true;
}
if ((elem.errType != GARD_Reconfig) &&
(elem.recordId == GUARD_RESOLVED))
{
Expand All @@ -28,7 +45,6 @@ void guardList(bool displayResolved)
std::cout << " | ";
std::cout << std::hex << std::setw(8) << std::setfill('0')
<< elem.elogId;

std::cout << " | ";
std::optional<std::string> gReasonToStr =
guardReasonToStr(elem.errType);
Expand All @@ -49,6 +65,11 @@ void guardList(bool displayResolved)
}
else
{
if ((elem.recordId != GUARD_RESOLVED) && !isHeaderPrinted)
{
printHeader(true);
isHeaderPrinted = true;
}
if ((elem.errType != GARD_Reconfig) &&
(elem.recordId != GUARD_RESOLVED))
{
Expand All @@ -57,7 +78,6 @@ void guardList(bool displayResolved)
std::cout << " | ";
std::cout << std::hex << std::setw(8) << std::setfill('0')
<< elem.elogId;

std::cout << " | ";
std::optional<std::string> gReasonToStr =
guardReasonToStr(elem.errType);
Expand All @@ -77,6 +97,10 @@ void guardList(bool displayResolved)
}
}
}
if (!isHeaderPrinted)
{
printHeader(false);
}
}

void guardDelete(const std::string& physicalPath)
Expand Down
2 changes: 1 addition & 1 deletion libguard/guard_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void fileSizeCheck(size_t size, uint32_t count)
{
// Delete the oldest resolved guard record, so that new guard
// record can be created.
clearResolvedRecords();
clearResolvedRecord();

GuardFile file(guardFilePath);
for_each_guard(file, pos, record)
Expand Down

0 comments on commit 0dd4d16

Please sign in to comment.