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>
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 @@
"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 @@
}
}
}
- if (ret.empty())
- {
- throw NotFoundException();
- }
return ret;
});
@@ -855,9 +864,17 @@
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 @@
}
}
}
- if (ret.empty())
- {
- throw NotFoundException();
- }
+
return ret;
});
@@ -909,9 +923,17 @@
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 @@
}
}
}
- if (ret.empty())
- {
- throw NotFoundException();
- }
+
return ret;
});