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/configure.ac b/configure.ac
index 7c9278c..eeabcfa 100755
--- a/configure.ac
+++ b/configure.ac
@@ -54,18 +54,16 @@
 
 AC_DEFINE(VERSION_IFACE, "xyz.openbmc_project.Software.Version",
     [The software version manager interface])
+AC_DEFINE(FILEPATH_IFACE, "xyz.openbmc_project.Common.FilePath",
+    [The common file path interface])
 
 AC_DEFINE(BUSNAME_UPDATER, "org.open_power.Software.Host.Updater",
     [The item updater DBus busname to own.])
 
 AC_ARG_VAR(MANIFEST_FILE, [The path to the MANIFEST file])
-AS_IF([test "x$MANIFEST_FILE" == "x"], [MANIFEST_FILE="/tmp/images/MANIFEST"])
+AS_IF([test "x$MANIFEST_FILE" == "x"], [MANIFEST_FILE="MANIFEST"])
 AC_DEFINE_UNQUOTED([MANIFEST_FILE], ["$MANIFEST_FILE"], [The path to the MANIFEST file])
 
-AC_ARG_VAR(IMAGE_DIR, [The path to all the IMAGE files])
-AS_IF([test "x$IMAGE_DIR" == "x"], [IMAGE_DIR="/tmp/images/"])
-AC_DEFINE_UNQUOTED([IMAGE_DIR], ["$IMAGE_DIR"], [The path to all the IMAGE files])
-
 AC_DEFINE(MAPPER_BUSNAME, "xyz.openbmc_project.ObjectMapper",
     [The object mapper busname.])
 AC_DEFINE(MAPPER_PATH, "/xyz/openbmc_project/object_mapper",
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)
diff --git a/item_updater.hpp b/item_updater.hpp
index 97f5005..82df3e7 100755
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -60,11 +60,11 @@
         /**
          * @brief Validates the presence of SquashFS iamge in the image dir.
          *
-         * @param[in]  versionId - The software version ID.
+         * @param[in]  filePath - The path to the SquashfFS image.
          * @param[out] result    - 0 --> if validation was successful
          *                       - -1--> Otherwise
          */
-        static int validateSquashFSImage(const std::string& versionId);
+        static int validateSquashFSImage(const std::string& filePath);
 
         /** @brief Persistent sdbusplus DBus bus connection. */
         sdbusplus::bus::bus& bus;