Add check for hwmon directory existence

For the power supplies, if a power supply is not present, the hwmon
subdirectory will not exist. Add in a check for directory existence to
avoid a termination.

Change-Id: I6e19e381602c2ef619c1e27f5ceacbf92c300cee
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/pmbus.cpp b/pmbus.cpp
index a289401..5fbbe3e 100644
--- a/pmbus.cpp
+++ b/pmbus.cpp
@@ -195,15 +195,21 @@
     fs::path path{basePath};
     path /= "hwmon";
 
-    //look for <basePath>/hwmon/hwmonN/
-    for (auto& f : fs::directory_iterator(path))
+    // Make sure the directory exists, otherwise for things that can be
+    // dynamically present or not present an exception will be thrown if the
+    // hwmon directory is not there, resulting in a program termination.
+    if (fs::is_directory(path))
     {
-        if ((f.path().filename().string().find("hwmon") !=
-             std::string::npos) &&
-            (fs::is_directory(f.path())))
+        //look for <basePath>/hwmon/hwmonN/
+        for (auto& f : fs::directory_iterator(path))
         {
-            hwmonDir = f.path().filename();
-            break;
+            if ((f.path().filename().string().find("hwmon") !=
+                 std::string::npos) &&
+                (fs::is_directory(f.path())))
+            {
+                hwmonDir = f.path().filename();
+                break;
+            }
         }
     }
 
@@ -211,9 +217,9 @@
     //and let accesses fail later
     if (hwmonDir.empty())
     {
-        log<level::ERR>("Unable to find hwmon directory "
-                        "in device base path",
-                        entry("DEVICE_PATH=%s", basePath.c_str()));
+        log<level::INFO>("Unable to find hwmon directory "
+                         "in device base path",
+                         entry("DEVICE_PATH=%s", basePath.c_str()));
     }
 
 }