Delete the BMC version that doesn't have a  valid os-release file.

- When a bmc rofs volume is corrupted, it no longer has a valid
  os-release. This had caused the BMC.Updater service to core-dump.
  We need to delete corrupted volumes in order to prevent such
  versions from filling up the space on chip.

Change-Id: I7f23382891dfd9b4dba40ffc1dc3084e088e92b1
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 9f79963..85fc8ed 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -158,12 +158,16 @@
         if (0 == iter.path().native().compare(0, BMC_RO_PREFIX_LEN,
                                               BMC_ROFS_PREFIX))
         {
+            // The versionId is extracted from the path
+            // for example /media/ro-2a1022fe.
+            auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN);
             auto osRelease = iter.path() / OS_RELEASE_FILE;
             if (!fs::is_regular_file(osRelease))
             {
                 log<level::ERR>("Failed to read osRelease\n",
                                 entry("FileName=%s", osRelease.string()));
-                activationState = server::Activation::Activations::Invalid;
+                ItemUpdater::erase(id);
+                continue;
             }
             auto version = VersionClass::getBMCVersion(osRelease);
             if (version.empty())
@@ -172,9 +176,7 @@
                                 entry("FILENAME=%s", osRelease.string()));
                 activationState = server::Activation::Activations::Invalid;
             }
-            // The versionId is extracted from the path
-            // for example /media/ro-2a1022fe
-            auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN);
+
             auto purpose = server::Version::VersionPurpose::BMC;
             auto path = fs::path(SOFTWARE_OBJPATH) / id;