item_updater: Use Common.FilePath to locate images

The image manager implements the Common.FilePath.Path interface,
make use of it to find the image files instead of hardcoding the
path, since the updater shouldn't know/care where the images are.

Change-Id: Ieb9ad8e393a7f91645631db9f302095eb82d7f61
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index efff65f..cd12688 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -32,6 +32,7 @@
                       sdbusplus::message::variant<std::string>>> interfaces;
     msg.read(objPath, interfaces);
     std::string path(std::move(objPath));
+    std::string filePath;
 
     for (const auto& intf : interfaces)
     {
@@ -53,8 +54,20 @@
                 }
             }
         }
+        else if (intf.first == FILEPATH_IFACE)
+        {
+            for (const auto& property : intf.second)
+            {
+                if (property.first == "Path")
+                {
+                    filePath = sdbusplus::message::variant_ns::get<
+                            std::string>(property.second);
+                }
+            }
+        }
     }
     if (version.empty() ||
+        filePath.empty() ||
         (purpose != server::Version::VersionPurpose::BMC &&
         purpose != server::Version::VersionPurpose::System))
     {
@@ -77,15 +90,11 @@
         // Determine the Activation state by processing the given image dir.
         auto activationState = server::Activation::Activations::Invalid;
         ItemUpdater::ActivationStatus result = ItemUpdater::
-                     validateSquashFSImage(versionId);
+                     validateSquashFSImage(filePath);
         if (result == ItemUpdater::ActivationStatus::ready)
         {
             activationState = server::Activation::Activations::Ready;
         }
-        else if (result == ItemUpdater::ActivationStatus::active)
-        {
-            activationState = server::Activation::Activations::Active;
-        }
         activations.insert(std::make_pair(
                                versionId,
                                std::make_unique<Activation>(
@@ -101,7 +110,7 @@
                                 path,
                                 version,
                                 purpose,
-                                "")));
+                                filePath)));
     }
     return;
 }
@@ -132,19 +141,10 @@
 }
 
 ItemUpdater::ActivationStatus ItemUpdater::validateSquashFSImage(
-             const std::string& versionId)
+             const std::string& filePath)
 {
 
-    // TODO openbmc/openbmc#1715 Check the Common.FilePath to
-    //      determine the active image.
-    fs::path imageDirPath(IMG_UPLOAD_DIR);
-    imageDirPath /= versionId;
-    if (!fs::is_directory(imageDirPath))
-    {
-        return ItemUpdater::ActivationStatus::active;
-    }
-
-    fs::path file(imageDirPath);
+    fs::path file(filePath);
     file /= bmcImage;
     std::ifstream efile(file.c_str());
 
@@ -154,7 +154,7 @@
     }
     else
     {
-        log<level::ERR>("Failed to find the SquashFS image.");
+        log<level::ERR>("Failed to find the BMC image.");
         return ItemUpdater::ActivationStatus::invalid;
     }
 }