summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2018-11-13 11:11:36 -0600
committerMatt Spinler <spinler@us.ibm.com>2018-11-26 21:17:51 +0000
commit6a39e8c727efb53b5902904d932c6308eb7f393e (patch)
tree912030a2f801bc1a75e471e8f0f7b75817bbba96 /src
parent06e5d2fe297d15ac261a9452a3674a946b36c7ff (diff)
downloadphosphor-objmgr-6a39e8c727efb53b5902904d932c6308eb7f393e.tar.gz
phosphor-objmgr-6a39e8c727efb53b5902904d932c6308eb7f393e.zip
mapper: Don't fail on some empty results
To preserve the behavior of the original mapper, don't fail the GetSubTree, GetSubTreePaths, and GetAncestors calls if the results are empty, instead only fail if the passed in object path isn't valid. This is particularly important to preserve the REST API that requires this different behavior between empty results and bad paths. Change-Id: I7e808a5613ed66cba4ea1a179a880e5c3f597f2a Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp53
1 files changed, 36 insertions, 17 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 95c9acd..3ee6362 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -768,11 +768,24 @@ int main(int argc, char** argv)
"xyz.openbmc_project.ObjectMapper");
iface->register_method(
- "GetAncestors", [&interface_map](const std::string& req_path,
+ "GetAncestors", [&interface_map](std::string& req_path,
std::vector<std::string>& interfaces) {
// Interfaces need to be sorted for intersect to function
std::sort(interfaces.begin(), interfaces.end());
+ if (req_path.size() > 1)
+ {
+ if (req_path.back() == '/')
+ {
+ req_path.pop_back();
+ }
+
+ if (interface_map.find(req_path) == interface_map.end())
+ {
+ throw NotFoundException();
+ }
+ }
+
std::vector<interface_map_type::value_type> ret;
for (auto& object_path : interface_map)
{
@@ -800,10 +813,6 @@ int main(int argc, char** argv)
}
}
}
- if (ret.empty())
- {
- throw NotFoundException();
- }
return ret;
});
@@ -855,9 +864,17 @@ 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 && req_path.back() == '/')
+ if (req_path.size() > 1)
{
- req_path.pop_back();
+ if (req_path.back() == '/')
+ {
+ req_path.pop_back();
+ }
+
+ if (interface_map.find(req_path) == interface_map.end())
+ {
+ throw NotFoundException();
+ }
}
for (auto& object_path : interface_map)
@@ -890,10 +907,7 @@ int main(int argc, char** argv)
}
}
}
- if (ret.empty())
- {
- throw NotFoundException();
- }
+
return ret;
});
@@ -909,9 +923,17 @@ int main(int argc, char** argv)
std::sort(interfaces.begin(), interfaces.end());
std::vector<std::string> ret;
- if (req_path.size() > 1 && req_path.back() == '/')
+ if (req_path.size() > 1)
{
- req_path.pop_back();
+ if (req_path.back() == '/')
+ {
+ req_path.pop_back();
+ }
+
+ if (interface_map.find(req_path) == interface_map.end())
+ {
+ throw NotFoundException();
+ }
}
for (auto& object_path : interface_map)
@@ -950,10 +972,7 @@ int main(int argc, char** argv)
}
}
}
- if (ret.empty())
- {
- throw NotFoundException();
- }
+
return ret;
});
OpenPOWER on IntegriCloud