Make MEDIA_DIR configurable

MEDIA_DIR was configured as "/media", it works on ubi-fs systems.

On static layout systems, "/media" is in rwfs, and thus is persistent
after BMC reboot or code update (if rwfs is not updated).
This makes the dirs/files in MEDIA_DIR persistent, and it causes an
issue that BMC uses the incorrect versionId of the image that is the
persistent one in MEDIA_DIR, while it should generate the versionID from
the functional BMC version.

Making MEDIA_DIR configurable, so static layout system could configure
it to a tmpfs, and the above issue is fixed.

Partly resolves openbmc/phosphor-bmc-code-mgmt#3

Tested: Verify that MEDIA_DIR could be configured via configure
        argument.

Change-Id: I10d46ea00b79677bec16ac69d2a3375597665f0c
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index e2d0f94..014757d 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -134,6 +134,21 @@
 void ItemUpdater::processBMCImage()
 {
     using VersionClass = phosphor::software::manager::Version;
+
+    // Check MEDIA_DIR and create if it does not exist
+    try
+    {
+        if (!fs::is_directory(MEDIA_DIR))
+        {
+            fs::create_directory(MEDIA_DIR);
+        }
+    }
+    catch (const fs::filesystem_error& e)
+    {
+        log<level::ERR>("Failed to prepare dir", entry("ERR=%s", e.what()));
+        return;
+    }
+
     // Read os-release from /etc/ to get the functional BMC version
     auto functionalVersion = VersionClass::getBMCVersion(OS_RELEASE_FILE);
 
@@ -172,7 +187,8 @@
             auto purpose = server::Version::VersionPurpose::BMC;
             auto path = fs::path(SOFTWARE_OBJPATH) / id;
 
-            // Create functional association if this is the functional version
+            // Create functional association if this is the functional
+            // version
             if (version.compare(functionalVersion) == 0)
             {
                 createFunctionalAssociation(path);
@@ -209,7 +225,8 @@
                 id, std::make_unique<Activation>(
                         bus, path, *this, id, activationState, associations)));
 
-            // If Active, create RedundancyPriority instance for this version.
+            // If Active, create RedundancyPriority instance for this
+            // version.
             if (activationState == server::Activation::Activations::Active)
             {
                 uint8_t priority = std::numeric_limits<uint8_t>::max();