diff options
author | Ed Tanous <ed@tanous.net> | 2020-12-18 03:41:31 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2021-02-19 20:51:28 +0300 |
commit | 2dfd18ef79d3b0a2995ba731983479d492be5949 (patch) | |
tree | dec1bda8ae27cbee65a983929b994515957beb3c /redfish-core/lib/hypervisor_system.hpp | |
parent | cb2ed190a7890e7ec3e6f5bde74e4d0abdee4bd1 (diff) | |
download | bmcweb-2dfd18ef79d3b0a2995ba731983479d492be5949.tar.xz |
Start using sdbusplus::message::filename()
Lots of code gets checked in that does this path checking incorrectly.
So much so, that we have it documented in COMMON_ERRORS.md, yet, we
persist. This patchset starts using the new object_path::filename()
method that was added recently to sdbusplus. Overall, it deletes code,
and makes for a much better developer experience.
Tested:
Pulled down several endpoints and verified that filename() method works
properly, and the collections are returned as expected.
curl -vvvv --insecure --user root:0penBmc https://192.168.7.2/redfish/v1/AccountService/Accounts
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ief1e0584394fb139678d3453265f7011bc931f3c
Diffstat (limited to 'redfish-core/lib/hypervisor_system.hpp')
-rw-r--r-- | redfish-core/lib/hypervisor_system.hpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp index eff9c3c712..290bac7188 100644 --- a/redfish-core/lib/hypervisor_system.hpp +++ b/redfish-core/lib/hypervisor_system.hpp @@ -123,14 +123,17 @@ class HypervisorInterfaceCollection : public Node ifaceArray = nlohmann::json::array(); for (const std::string& iface : ifaceList) { - std::size_t lastPos = iface.rfind('/'); - if (lastPos != std::string::npos) + sdbusplus::message::object_path path(iface); + std::string name = path.filename(); + if (name.empty()) { - ifaceArray.push_back( - {{"@odata.id", "/redfish/v1/Systems/hypervisor/" - "EthernetInterfaces/" + - iface.substr(lastPos + 1)}}); + continue; } + + ifaceArray.push_back( + {{"@odata.id", "/redfish/v1/Systems/hypervisor/" + "EthernetInterfaces/" + + name}}); } asyncResp->res.jsonValue["Members@odata.count"] = ifaceArray.size(); |