Create image dir if needed

Change-Id: If1c1a62292027ae98d1ba1c6d62bd72d0ae8a307
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index e4be065..9de41b4 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,7 +28,8 @@
 	$(SYSTEMD_LIBS) \
 	$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
 	$(SDBUSPLUS_LIBS) \
-	$(PHOSPHOR_LOGGING_LIBS)
+	$(PHOSPHOR_LOGGING_LIBS) \
+	-lstdc++fs
 
 phosphor_version_software_manager_CXXFLAGS = $(generic_cxxflags)
 phosphor_version_software_manager_LDFLAGS = $(generic_ldflags)
diff --git a/download_manager.cpp b/download_manager.cpp
index f5ff54b..fc217f0 100644
--- a/download_manager.cpp
+++ b/download_manager.cpp
@@ -3,6 +3,7 @@
 #include <unistd.h>
 #include <sys/wait.h>
 #include <phosphor-logging/log.hpp>
+#include <experimental/filesystem>
 #include "config.h"
 #include <phosphor-logging/elog.hpp>
 #include <phosphor-logging/elog-errors.hpp>
@@ -18,6 +19,7 @@
 
 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
 using namespace phosphor::logging;
+namespace fs = std::experimental::filesystem;
 
 void Download::downloadViaTFTP(const  std::string fileName,
                                const  std::string serverAddress)
@@ -46,6 +48,13 @@
                      entry("FILENAME=%s", fileName),
                      entry("SERVERADDRESS=%s", serverAddress));
 
+    // Check if IMAGE DIR exists and create if necessary.
+    fs::path imgDirPath(IMG_UPLOAD_DIR);
+    if (!fs::is_directory(imgDirPath))
+    {
+        fs::create_directory(imgDirPath);
+    }
+
     pid_t pid = fork();
 
     if (pid == 0)