utils: Add function to get the latest version
This repo does not know which PSU version is the latest, and it lets the
vendor tool to decide which one is the latest.
This commit defines PSU_VERSION_COMPARE_UTIL which is expected to be a
tool that accepts arguments of a list of versions, and returns the
latest version string.
Tested: Put and configure to use the example get_latest_version on
Witherspoon, verify the versionId with a larger version string
is returned.
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: Ic5a10d3724cf6a98b3979486c72d54f8deac7038
diff --git a/src/utils.cpp b/src/utils.cpp
index 33e56be..171de29 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -154,6 +154,21 @@
return (rc == 0) ? r : "";
}
+std::string Utils::getLatestVersion(const std::set<std::string>& versions) const
+{
+ if (versions.empty())
+ {
+ return {};
+ }
+ std::stringstream args;
+ for (const auto& s : versions)
+ {
+ args << s << " ";
+ }
+ auto [rc, r] = internal::exec(PSU_VERSION_COMPARE_UTIL, args.str());
+ return (rc == 0) ? r : "";
+}
+
any Utils::getPropertyImpl(sdbusplus::bus::bus& bus, const char* service,
const char* path, const char* interface,
const char* propertyName) const