diff options
author | James Feist <james.feist@linux.intel.com> | 2019-01-28 11:25:00 -0800 |
---|---|---|
committer | James Feist <james.feist@linux.intel.com> | 2019-01-28 20:48:42 +0000 |
commit | d732287cdd988b4ad79718a6adcb4ba81c023de2 (patch) | |
tree | ffbfaadee4b080f9bce8e8940589224bb0f934c8 | |
parent | a82779fb66e30b0387077c28e6aec2dc1a957a61 (diff) | |
download | phosphor-objmgr-d732287cdd988b4ad79718a6adcb4ba81c023de2.tar.gz phosphor-objmgr-d732287cdd988b4ad79718a6adcb4ba81c023de2.zip |
Fix looking for objects on root path
The current code would not remove the "/" for the root
path causing a subtree or other call with path being
"/" to miss any object exposed on "/". Fix this
so that "/" is removed when it is the only character.
Tested-by: Phosphor-pid-control stopped throwing when
looking for object managers.
Change-Id: I8ff49617d661910f22cc95409cd2df2489862b5f
Signed-off-by: James Feist <james.feist@linux.intel.com>
-rw-r--r-- | src/main.cpp | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/src/main.cpp b/src/main.cpp index d0282db..ab43597 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -883,17 +883,14 @@ int main(int argc, char** argv) // Interfaces need to be sorted for intersect to function std::sort(interfaces.begin(), interfaces.end()); - if (req_path.size() > 1) + if (boost::ends_with(req_path, "/")) { - if (req_path.back() == '/') - { - req_path.pop_back(); - } - - if (interface_map.find(req_path) == interface_map.end()) - { - throw NotFoundException(); - } + req_path.pop_back(); + } + if (req_path.size() && + interface_map.find(req_path) == interface_map.end()) + { + throw NotFoundException(); } std::vector<interface_map_type::value_type> ret; @@ -974,17 +971,14 @@ int main(int argc, char** argv) std::sort(interfaces.begin(), interfaces.end()); std::vector<interface_map_type::value_type> ret; - if (req_path.size() > 1) + if (boost::ends_with(req_path, "/")) { - if (req_path.back() == '/') - { - req_path.pop_back(); - } - - if (interface_map.find(req_path) == interface_map.end()) - { - throw NotFoundException(); - } + req_path.pop_back(); + } + if (req_path.size() && + interface_map.find(req_path) == interface_map.end()) + { + throw NotFoundException(); } for (auto& object_path : interface_map) @@ -1034,17 +1028,14 @@ int main(int argc, char** argv) std::sort(interfaces.begin(), interfaces.end()); std::vector<std::string> ret; - if (req_path.size() > 1) + if (boost::ends_with(req_path, "/")) { - if (req_path.back() == '/') - { - req_path.pop_back(); - } - - if (interface_map.find(req_path) == interface_map.end()) - { - throw NotFoundException(); - } + req_path.pop_back(); + } + if (req_path.size() && + interface_map.find(req_path) == interface_map.end()) + { + throw NotFoundException(); } for (auto& object_path : interface_map) |