Clear dump directory during manufacturing clean
This commit clears the vpd dump directory in case of manufacturing
clean.The vpd dump directory contains invalid vpd files found during
parsing. These files need to be deleted when manufacturing clean is
executed.
Test:
```
1. Ensure vpd-manager has dumped 3 bad VPD files in the VPD dump
directory.
2. Execute vpd-tool --mfgClean --yes
3. After manufacturing clean is done, check return code, should be 0.
4. After manufacturing clean is done, check the VPD dump directory in
/var/lib/vpd. There should be no dumps directory inside.
```
Change-Id: Ic8079013e8b6608b2365b3ce874f0950bf50d77a
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-tool/include/tool_constants.hpp b/vpd-tool/include/tool_constants.hpp
index 3201755..b813933 100644
--- a/vpd-tool/include/tool_constants.hpp
+++ b/vpd-tool/include/tool_constants.hpp
@@ -54,6 +54,7 @@
"xyz.openbmc_project.BIOSConfig.Manager";
constexpr auto KwdIM = "IM";
+constexpr auto badVpdPath = "/var/lib/vpd/dumps";
// Valid IM values list.
static std::vector<std::string> validImValues{
diff --git a/vpd-tool/include/vpd_tool.hpp b/vpd-tool/include/vpd_tool.hpp
index ed2aa00..3a8e85a 100644
--- a/vpd-tool/include/vpd_tool.hpp
+++ b/vpd-tool/include/vpd_tool.hpp
@@ -363,5 +363,13 @@
* @return On success returns 0, otherwise returns -1.
*/
int resetVpdOnDbus();
+
+ /**
+ * @brief API to clear vpd dump directory
+ *
+ * This API deletes all the files inside vpd dump directory and then deletes
+ * the directory from the filesystem
+ */
+ void clearVpdDumpDir() const noexcept;
};
} // namespace vpd
diff --git a/vpd-tool/src/vpd_tool.cpp b/vpd-tool/src/vpd_tool.cpp
index 786af8c..c275509 100644
--- a/vpd-tool/src/vpd_tool.cpp
+++ b/vpd-tool/src/vpd_tool.cpp
@@ -1540,4 +1540,22 @@
}
return l_result;
}
+
+void VpdTool::clearVpdDumpDir() const noexcept
+{
+ try
+ {
+ if (std::filesystem::exists(constants::badVpdPath))
+ {
+ std::filesystem::remove_all(constants::badVpdPath);
+ }
+ }
+ catch (const std::exception& l_ex)
+ {
+ std::cerr << "Failed to clear VPD dump path:[" +
+ std::string(constants::badVpdPath) + "]. Error: "
+ << l_ex.what() << std::endl;
+ }
+}
+
} // namespace vpd
diff --git a/vpd-tool/src/vpd_tool_main.cpp b/vpd-tool/src/vpd_tool_main.cpp
index 152cfca..e0bbf7a 100644
--- a/vpd-tool/src/vpd_tool_main.cpp
+++ b/vpd-tool/src/vpd_tool_main.cpp
@@ -62,6 +62,10 @@
}
vpd::VpdTool l_vpdToolObj;
+
+ // delete the vpd dump directory
+ l_vpdToolObj.clearVpdDumpDir();
+
return l_vpdToolObj.cleanSystemVpd(!i_syncBiosAttributesFlag->empty());
}