Restore dump d-bus objects during daemon starts
Use the dump files in the persistant location to rebuild the
d-bus objects.
Change-Id: Ia7b478649274a4681c802e11be4b2049eeed8e13
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/dump_manager.cpp b/dump_manager.cpp
index 7e753c0..3775842 100644
--- a/dump_manager.cpp
+++ b/dump_manager.cpp
@@ -16,7 +16,6 @@
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace phosphor::logging;
-using namespace std;
namespace internal
{
@@ -170,5 +169,35 @@
childWatchMap.erase(path);
}
+void Manager::restore()
+{
+ fs::path dir(BMC_DUMP_PATH);
+ if (!fs::exists(dir) || fs::is_empty(dir))
+ {
+ return;
+ }
+
+ //Dump file path: <BMC_DUMP_PATH>/<id>/<filename>
+ for (const auto& p : fs::directory_iterator(dir))
+ {
+ auto idStr = p.path().filename().string();
+
+ //Consider only directory's with dump id as name.
+ //Note: As per design one file per directory.
+ if ((fs::is_directory(p.path())) &&
+ std::all_of(idStr.begin(), idStr.end(), ::isdigit))
+ {
+ lastEntryId = std::max(lastEntryId,
+ static_cast<uint32_t>(std::stoul(idStr)));
+ auto fileIt = fs::directory_iterator(p.path());
+ //Create dump entry d-bus object.
+ if (fileIt != fs::end(fileIt))
+ {
+ createEntry(fileIt->path());
+ }
+ }
+ }
+}
+
} //namespace dump
} //namespace phosphor