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/serialize.cpp b/serialize.cpp
index 52c5ac5..8b7fca4 100644
--- a/serialize.cpp
+++ b/serialize.cpp
@@ -22,9 +22,9 @@
 const std::string priorityName = "priority";
 const std::string purposeName = "purpose";
 
-void storePriority(const std::string& versionId, uint8_t priority)
+void storePriority(const std::string& flashId, uint8_t priority)
 {
-    auto path = fs::path(PERSIST_DIR) / versionId;
+    auto path = fs::path(PERSIST_DIR) / flashId;
     if (!fs::is_directory(path))
     {
         if (fs::exists(path))
@@ -42,9 +42,9 @@
     oarchive(cereal::make_nvp(priorityName, priority));
 }
 
-void storePurpose(const std::string& versionId, VersionPurpose purpose)
+void storePurpose(const std::string& flashId, VersionPurpose purpose)
 {
-    auto path = fs::path(PERSIST_DIR) / versionId;
+    auto path = fs::path(PERSIST_DIR) / flashId;
     if (!fs::is_directory(path))
     {
         if (fs::exists(path))
@@ -62,9 +62,9 @@
     oarchive(cereal::make_nvp(purposeName, purpose));
 }
 
-bool restorePriority(const std::string& versionId, uint8_t& priority)
+bool restorePriority(const std::string& flashId, uint8_t& priority)
 {
-    auto path = fs::path(PERSIST_DIR) / versionId / priorityName;
+    auto path = fs::path(PERSIST_DIR) / flashId / priorityName;
     if (fs::exists(path))
     {
         std::ifstream is(path.c_str(), std::ios::in);
@@ -101,13 +101,13 @@
             std::string envVars;
             std::getline(input, envVars);
 
-            std::string versionVar = versionId + "=";
+            std::string versionVar = flashId + "=";
             auto varPosition = envVars.find(versionVar);
 
             if (varPosition != std::string::npos)
             {
-                // Grab the environment variable for this versionId. These
-                // variables follow the format "versionId=priority\0"
+                // Grab the environment variable for this flashId. These
+                // variables follow the format "flashId=priority\0"
                 auto var = envVars.substr(varPosition);
                 priority = std::stoi(var.substr(versionVar.length()));
                 return true;
@@ -122,9 +122,9 @@
     return false;
 }
 
-bool restorePurpose(const std::string& versionId, VersionPurpose& purpose)
+bool restorePurpose(const std::string& flashId, VersionPurpose& purpose)
 {
-    auto path = fs::path(PERSIST_DIR) / versionId / purposeName;
+    auto path = fs::path(PERSIST_DIR) / flashId / purposeName;
     if (fs::exists(path))
     {
         std::ifstream is(path.c_str(), std::ios::in);
@@ -143,9 +143,9 @@
     return false;
 }
 
-void removePersistDataDirectory(const std::string& versionId)
+void removePersistDataDirectory(const std::string& flashId)
 {
-    auto path = fs::path(PERSIST_DIR) / versionId;
+    auto path = fs::path(PERSIST_DIR) / flashId;
     if (fs::exists(path))
     {
         fs::remove_all(path);