serialize: Use flash id instead of version id

Update the serialize functions to take the flash id instead of the
version id since version id can be different every time the BMC boots up
once support for uploading the same version is added.

For the erase() function, if the flash id cannot be determined, it won't
be able to clean up the serialize directory since it doesn't know the
name for it, but this should be a rare scenario since the flash id (Path
property) is set when the BMC boots up.

Tested: The serialize directory name remains the same for ubi (version
id), and it changes to "a" or "b" for mmc. The priority of the versions
are found and restored upon reboot.

Change-Id: Ic2bd39caadbf7147e30200be8c4080f2b030c17a
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 550f845..e7de3d0 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -227,8 +227,11 @@
                 continue;
             }
 
+            // The flash location is part of the mount name: rofs-<location>
+            auto flashId = iter.path().native().substr(BMC_RO_PREFIX_LEN);
+
             auto purpose = server::Version::VersionPurpose::BMC;
-            restorePurpose(id, purpose);
+            restorePurpose(flashId, purpose);
 
             // Read os-release from /etc/ to get the BMC extended version
             std::string extendedVersion =
@@ -260,9 +263,6 @@
             // association.
             createUpdateableAssociation(path);
 
-            // The flash location is part of the mount name: rofs-<location>
-            auto flashId = iter.path().native().substr(BMC_RO_PREFIX_LEN);
-
             // Create Version instance for this version.
             auto versionPtr = std::make_unique<VersionClass>(
                 bus, path, version, purpose, extendedVersion, flashId,
@@ -286,7 +286,7 @@
             if (activationState == server::Activation::Activations::Active)
             {
                 uint8_t priority = std::numeric_limits<uint8_t>::max();
-                if (!restorePriority(id, priority))
+                if (!restorePriority(flashId, priority))
                 {
                     if (isVersionFunctional)
                     {
@@ -373,9 +373,11 @@
 
     if (it != versions.end())
     {
+        auto flashId = it->second->path();
+
         // Delete ReadOnly partitions if it's not active
         removeReadOnlyPartition(entryId);
-        removePersistDataDirectory(entryId);
+        removePersistDataDirectory(flashId);
 
         // Removing entry in versions map
         this->versions.erase(entryId);
@@ -384,7 +386,6 @@
     {
         // Delete ReadOnly partitions even if we can't find the version
         removeReadOnlyPartition(entryId);
-        removePersistDataDirectory(entryId);
 
         error(
             "Failed to find version ({VERSIONID}) in item updater versions map; unable to remove.",
@@ -442,7 +443,8 @@
 
 void ItemUpdater::savePriority(const std::string& versionId, uint8_t value)
 {
-    storePriority(versionId, value);
+    auto flashId = versions.find(versionId)->second->path();
+    storePriority(flashId, value);
     helper.setEntry(versionId, value);
 }