serialize: Store priority in directory instead of file

Currently the priority value is stored in <persist_dir>/<version_id>.

There is a need to persist the version purpose as well, because it
can be BMC or System. To achieve this, we can either store the priority
and purpose on different files under a single directory, or store both
values in the current single file.

Proposing to implement the former because cereal is not designed to
append data to a serialized file, therefore it'd be necessary to store
all the values every time a file is saved, and would make it confusing
having to somehow pass the priority and purpose values when updating
the priority. This would get more complicated as more files were added
to be persisted. Also the purpose only needs to be updated once, and
doesn't change, so makes sense to store different values that are stored
at different times in different files.

Proposed change:
- Store the values under <persiste_dir>/<version_id>/<property_name>.
- Change the persist directory to /var/lib/phosphor-bmc-code-mgmt/
  instead of /var/lib/obmc/phosphor-bmc-code-mgmt/. This allows for this
  change from file to directory to be backward compatible because the
  current code fails to do a remove if the version_id is a directory.
  This would also make the path consistent with the general guidelines
  (see https://lists.ozlabs.org/pipermail/openbmc/2019-November/019388.html)
  as the /var/lib/obmc/ directory is being deprecated eventually.
- Change the function names to specify they apply to priority values.

Tested: Verified the properties were stored in a directory, and updates
        and downgrades handled the values correctly, since if the value
        is not found in a file/directory, there's a backup value in U-Boot.

Change-Id: I244334af51721385c748fe06d2e3d029ede1d138
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/serialize.hpp b/serialize.hpp
index adaf018..9a9df09 100644
--- a/serialize.hpp
+++ b/serialize.hpp
@@ -13,23 +13,23 @@
 
 namespace fs = std::experimental::filesystem;
 
-/** @brief Serialization function - stores activation information to file
+/** @brief Serialization function - stores priority information to file
  *  @param[in] versionId - The version for which to store information.
  *  @param[in] priority - RedundancyPriority value for that version.
  **/
-void storeToFile(std::string versionId, uint8_t priority);
+void storePriority(const std::string& versionId, uint8_t priority);
 
-/** @brief Serialization function - restores activation information from file
+/** @brief Serialization function - restores priority information from file
  *  @param[in] versionId - The version for which to retrieve information.
  *  @param[in] priority - RedundancyPriority reference for that version.
  *  @return true if restore was successful, false if not
  **/
-bool restoreFromFile(std::string versionId, uint8_t& priority);
+bool restorePriority(const std::string& versionId, uint8_t& priority);
 
-/** @brief Removes the serial file for a given version.
+/** @brief Removes the serial directory for a given version.
  *  @param[in] versionId - The version for which to remove a file, if it exists.
  **/
-void removeFile(std::string versionId);
+void removePersistDataDirectory(const std::string& versionId);
 
 } // namespace updater
 } // namespace software