PEL: Don't partial match on peltool -i <id>
Previously, peltool -i <PEL ID> would still display a PEL if the ID
passed in was just a substring of the PEL ID.
For example, peltool -i 0x1 would print the first PEL it found that had
an ID that ended with '1'.
Fix this so that the ID passed in has to be the full 8 characters so it
won't match on a partial ID. Also rename the function that checks for
the match to reflect that it is doing a match for a PEL ID.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I3abfb88c47eadc23ef3c79ca184d0b38d3e4d3fe
diff --git a/extensions/openpower-pels/tools/peltool.cpp b/extensions/openpower-pels/tools/peltool.cpp
index f6329cc..3935371 100644
--- a/extensions/openpower-pels/tools/peltool.cpp
+++ b/extensions/openpower-pels/tools/peltool.cpp
@@ -184,19 +184,27 @@
}
/**
- * @brief helper function to check string suffix
- * @retrun bool - true with suffix matches
- * @param[in] std::string - string to check for suffix
- * @param[in] std::string - suffix string
+ * @brief Check if the string ends with the PEL ID string passed in
+ * @param[in] str - string to check for PEL ID
+ * @param[in] pelID - PEL id string
+ *
+ * @return bool - true with suffix matches
*/
-bool ends_with(const std::string& str, const std::string& end)
+bool endsWithPelID(const std::string& str, const std::string& pelID)
{
- size_t slen = str.size(), elen = end.size();
+ constexpr size_t pelIDSize = 8;
+
+ if (pelID.size() != pelIDSize)
+ {
+ return false;
+ }
+
+ size_t slen = str.size(), elen = pelID.size();
if (slen < elen)
return false;
while (elen)
{
- if (str[--slen] != end[--elen])
+ if (str[--slen] != pelID[--elen])
return false;
}
return true;
@@ -579,7 +587,7 @@
continue;
}
- if ((ends_with((*it).path(), pelID) && !useBMC) || useBMC)
+ if ((endsWithPelID((*it).path(), pelID) && !useBMC) || useBMC)
{
auto data = getFileData((*it).path());
if (!data.empty())
@@ -636,7 +644,7 @@
for (auto it = fs::directory_iterator(pelLogDir());
it != fs::directory_iterator(); ++it)
{
- if (ends_with((*it).path(), pelID))
+ if (endsWithPelID((*it).path(), pelID))
{
fs::remove((*it).path());
}