image_manager: Added erase method

Image manager deletes image, image directory,
and the version from its map.

Change-Id: Ica128927b706257eb8c4b28d3b9d2ac9ca397b91
Signed-off-by: Leonel Gonzalez <lgonzalez@us.ibm.com>
diff --git a/image_manager.cpp b/image_manager.cpp
index eaf2e6d..bc9ce9e 100644
--- a/image_manager.cpp
+++ b/image_manager.cpp
@@ -177,6 +177,22 @@
     return 0;
 }
 
+void Manager::erase(std::string entryId)
+{
+    auto it = versions.find(entryId);
+    if (it == versions.end())
+    {
+        return;
+    }
+    // Delete image dir
+    fs::path imageDirPath = (*(it->second)).path();
+    if (fs::exists(imageDirPath))
+    {
+        fs::remove_all(imageDirPath);
+    }
+    this->versions.erase(entryId);
+}
+
 int Manager::unTar(const std::string& tarFilePath,
                    const std::string& extractDirPath)
 {
diff --git a/image_manager.hpp b/image_manager.hpp
index 6e45c7c..b0b8b89 100644
--- a/image_manager.hpp
+++ b/image_manager.hpp
@@ -31,6 +31,14 @@
          */
          int processImage(const std::string& tarballFilePath);
 
+        /**
+         * @brief Erase specified entry d-bus object
+         *        and deletes the image file.
+         *
+         * @param[in] entryId - unique identifier of the entry
+         */
+        void erase(std::string entryId);
+
     private:
         /** @brief Persistent map of Version dbus objects and their
           * version id */