Sort collections by human sort
Today, collections of dimms have a weird issue where they sort by
lexicographical sort, not numeric sort, so systems with >10 dimms show up
in the order:
Dimm1
Dimm10
Dimm11
Dimm2
While these collections are supposed to be sets, and the order doesn't
matter in the spec, there are a number of humans that look at these, and
doing something obvious is good for people.
Tested:
Tested on a CI system with 16 dimms here:
https://gist.github.com/geissonator/53a94f124c3501691a7870fb80c60c80
Which responded with dimms 1 and 11 being in the correct order.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I0c8b28fd169c5a957fb4d36a7c6771473b06fc0c
diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp
index 4511f61..c5d603a 100644
--- a/redfish-core/include/utils/collection.hpp
+++ b/redfish-core/include/utils/collection.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include <boost/container/flat_map.hpp>
+#include <human_sort.hpp>
#include <string>
#include <vector>
@@ -46,9 +46,8 @@
messages::internalError(aResp->res);
return;
}
- nlohmann::json& members = aResp->res.jsonValue["Members"];
- members = nlohmann::json::array();
+ std::vector<std::string> pathNames;
for (const auto& object : objects)
{
sdbusplus::message::object_path path(object);
@@ -57,6 +56,15 @@
{
continue;
}
+ pathNames.push_back(leaf);
+ }
+ std::sort(pathNames.begin(), pathNames.end(),
+ AlphanumLess<std::string>());
+
+ nlohmann::json& members = aResp->res.jsonValue["Members"];
+ members = nlohmann::json::array();
+ for (const std::string& leaf : pathNames)
+ {
std::string newPath = collectionPath;
newPath += '/';
newPath += leaf;