BMC Updater: Add function to delete all versions
This commit extends the item updater with a function to delete all
non-current versions uploaded to the machine.
Resolves openbmc/openbmc#2264
Change-Id: I4d835d5020766f8bb5e9653b28535acfb191fe53
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index a19aebc..9f79963 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -297,6 +297,33 @@
this->activations.erase(entryId);
}
+void ItemUpdater::deleteAll()
+{
+ std::vector<std::string> deletableVersions;
+
+ for (const auto& versionIt : versions)
+ {
+ if (!versionIt.second->isFunctional())
+ {
+ deletableVersions.push_back(versionIt.first);
+ }
+ }
+
+ for (const auto& deletableIt : deletableVersions)
+ {
+ ItemUpdater::erase(deletableIt);
+ }
+
+ // Remove any volumes that do not match current versions.
+ auto method = bus.new_method_call(
+ SYSTEMD_BUSNAME,
+ SYSTEMD_PATH,
+ SYSTEMD_INTERFACE,
+ "StartUnit");
+ method.append("obmc-flash-bmc-cleanup.service", "replace");
+ bus.call_noreply(method);
+}
+
ItemUpdater::ActivationStatus ItemUpdater::validateSquashFSImage(
const std::string& filePath)
{