item_updater: Use the Common.FilePath.Path to find the image files

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: Ie9ec5982af1ec2ddd6d7a1b9e69d518520225ab5
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index a8809e6..fa1c38d 100755
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -1,4 +1,5 @@
 #include <string>
+#include <experimental/filesystem>
 #include <fstream>
 #include <phosphor-logging/log.hpp>
 #include <xyz/openbmc_project/Software/Version/server.hpp>
@@ -15,6 +16,7 @@
 
 // When you see server:: you know we're referencing our base class
 namespace server = sdbusplus::xyz::openbmc_project::Software::server;
+namespace fs = std::experimental::filesystem;
 
 using namespace phosphor::logging;
 
@@ -29,6 +31,8 @@
     m.read(objPath, interfaces);
     std::string path(std::move(objPath));
 
+    std::string filePath;
+
     for (const auto& intf : interfaces)
     {
         if (intf.first == VERSION_IFACE)
@@ -50,9 +54,23 @@
                 }
             }
         }
+        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 (filePath.empty())
+    {
+        return;
     }
 
-    auto extendedVersion = ItemUpdater::getExtendedVersion(MANIFEST_FILE);
     // Version id is the last item in the path
     auto pos = path.rfind("/");
     if (pos == std::string::npos)
@@ -68,7 +86,7 @@
     {
         // Determine the Activation state by processing the given image dir.
         auto activationState = server::Activation::Activations::Invalid;
-        if (ItemUpdater::validateSquashFSImage(versionId) == 0)
+        if (ItemUpdater::validateSquashFSImage(filePath) == 0)
         {
             activationState = server::Activation::Activations::Ready;
 
@@ -90,6 +108,9 @@
             bus.call_noreply(method);
         }
 
+        fs::path manifestPath(filePath);
+        manifestPath /= MANIFEST_FILE;
+        auto extendedVersion = ItemUpdater::getExtendedVersion(manifestPath);
         activations.insert(std::make_pair(
                 versionId,
                 std::make_unique<Activation>(
@@ -141,10 +162,10 @@
     return extendedVersion;
 }
 
-int ItemUpdater::validateSquashFSImage(const std::string& versionId)
+int ItemUpdater::validateSquashFSImage(const std::string& filePath)
 {
-    auto file = IMAGE_DIR + versionId + "/" +
-                std::string(squashFSImage);
+    fs::path file(filePath);
+    file /= squashFSImage;
     std::ifstream efile(file.c_str());
 
     if (efile.good() == 1)