c++17: drop experimental::filesystem

Use the real filesystem library, and drop support for building with
experimental under c++14.

Change-Id: I47cbfc30b223db9dc28e9536ceb84e9fe3342e96
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/ubi/activation_ubi.cpp b/ubi/activation_ubi.cpp
index 97358e8..946a741 100644
--- a/ubi/activation_ubi.cpp
+++ b/ubi/activation_ubi.cpp
@@ -5,7 +5,7 @@
 
 #include <phosphor-logging/log.hpp>
 
-#include <experimental/filesystem>
+#include <filesystem>
 
 namespace openpower
 {
@@ -13,7 +13,6 @@
 {
 namespace updater
 {
-namespace fs = std::experimental::filesystem;
 namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
 using namespace phosphor::logging;
 
@@ -63,9 +62,9 @@
             // verify that this happened, we check for the mount dirs PNOR_PRSV
             // and PNOR_RW_PREFIX_<versionid>, as well as the image dir R0.
 
-            if ((fs::is_directory(PNOR_PRSV)) &&
-                (fs::is_directory(PNOR_RW_PREFIX + versionId)) &&
-                (fs::is_directory(PNOR_RO_PREFIX + versionId)))
+            if ((std::filesystem::is_directory(PNOR_PRSV)) &&
+                (std::filesystem::is_directory(PNOR_RW_PREFIX + versionId)) &&
+                (std::filesystem::is_directory(PNOR_RO_PREFIX + versionId)))
             {
                 finishActivation();
                 if (Activation::checkApplyTimeImmediate())
diff --git a/ubi/item_updater_ubi.cpp b/ubi/item_updater_ubi.cpp
index ee87965..9b8897b 100644
--- a/ubi/item_updater_ubi.cpp
+++ b/ubi/item_updater_ubi.cpp
@@ -12,7 +12,7 @@
 #include <phosphor-logging/log.hpp>
 #include <xyz/openbmc_project/Software/Version/server.hpp>
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <fstream>
 #include <queue>
 #include <string>
@@ -26,7 +26,6 @@
 
 // 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 sdbusplus::xyz::openbmc_project::Common::Error;
 using namespace phosphor::logging;
@@ -65,7 +64,7 @@
 {
     // Read pnor.toc from folders under /media/
     // to get Active Software Versions.
-    for (const auto& iter : fs::directory_iterator(MEDIA_DIR))
+    for (const auto& iter : std::filesystem::directory_iterator(MEDIA_DIR))
     {
         auto activationState = server::Activation::Activations::Active;
 
@@ -80,7 +79,7 @@
             // for example /media/pnor-ro-2a1022fe.
             auto id = iter.path().native().substr(PNOR_RO_PREFIX_LEN);
             auto pnorTOC = iter.path() / PNOR_TOC_FILE;
-            if (!fs::is_regular_file(pnorTOC))
+            if (!std::filesystem::is_regular_file(pnorTOC))
             {
                 log<level::ERR>("Failed to read pnorTOC.",
                                 entry("FILENAME=%s", pnorTOC.c_str()));
@@ -106,7 +105,7 @@
             }
 
             auto purpose = server::Version::VersionPurpose::Host;
-            auto path = fs::path(SOFTWARE_OBJPATH) / id;
+            auto path = std::filesystem::path(SOFTWARE_OBJPATH) / id;
             AssociationList associations = {};
 
             if (activationState == server::Activation::Activations::Active)
@@ -157,7 +156,7 @@
         {
             auto id = iter.path().native().substr(PNOR_RW_PREFIX_LEN);
             auto roDir = PNOR_RO_PREFIX + id;
-            if (!fs::is_directory(roDir))
+            if (!std::filesystem::is_directory(roDir))
             {
                 log<level::ERR>("No corresponding read-only volume found.",
                                 entry("DIRNAME=%s", roDir.c_str()));
@@ -177,8 +176,8 @@
 
 int ItemUpdaterUbi::validateSquashFSImage(const std::string& filePath)
 {
-    auto file = fs::path(filePath) / squashFSImage;
-    if (fs::is_regular_file(file))
+    auto file = std::filesystem::path(filePath) / squashFSImage;
+    if (std::filesystem::is_regular_file(file))
     {
         return 0;
     }
@@ -216,11 +215,11 @@
     utils::hiomapdSuspend(bus);
 
     constexpr static auto patchDir = "/usr/local/share/pnor";
-    if (fs::is_directory(patchDir))
+    if (std::filesystem::is_directory(patchDir))
     {
-        for (const auto& iter : fs::directory_iterator(patchDir))
+        for (const auto& iter : std::filesystem::directory_iterator(patchDir))
         {
-            fs::remove_all(iter);
+            std::filesystem::remove_all(iter);
         }
     }
 
@@ -228,21 +227,21 @@
     for (const auto& it : activations)
     {
         auto rwDir = PNOR_RW_PREFIX + it.first;
-        if (fs::is_directory(rwDir))
+        if (std::filesystem::is_directory(rwDir))
         {
-            for (const auto& iter : fs::directory_iterator(rwDir))
+            for (const auto& iter : std::filesystem::directory_iterator(rwDir))
             {
-                fs::remove_all(iter);
+                std::filesystem::remove_all(iter);
             }
         }
     }
 
     // Clear the preserved partition.
-    if (fs::is_directory(PNOR_PRSV))
+    if (std::filesystem::is_directory(PNOR_PRSV))
     {
-        for (const auto& iter : fs::directory_iterator(PNOR_PRSV))
+        for (const auto& iter : std::filesystem::directory_iterator(PNOR_PRSV))
         {
-            fs::remove_all(iter);
+            std::filesystem::remove_all(iter);
         }
     }
 
@@ -251,14 +250,15 @@
 
 bool ItemUpdaterUbi::isVersionFunctional(const std::string& versionId)
 {
-    if (!fs::exists(PNOR_RO_ACTIVE_PATH))
+    if (!std::filesystem::exists(PNOR_RO_ACTIVE_PATH))
     {
         return false;
     }
 
-    fs::path activeRO = fs::read_symlink(PNOR_RO_ACTIVE_PATH);
+    std::filesystem::path activeRO =
+        std::filesystem::read_symlink(PNOR_RO_ACTIVE_PATH);
 
-    if (!fs::is_directory(activeRO))
+    if (!std::filesystem::is_directory(activeRO))
     {
         return false;
     }
@@ -393,15 +393,15 @@
 
 std::string ItemUpdaterUbi::determineId(const std::string& symlinkPath)
 {
-    if (!fs::exists(symlinkPath))
+    if (!std::filesystem::exists(symlinkPath))
     {
         return {};
     }
 
-    auto target = fs::canonical(symlinkPath).string();
+    auto target = std::filesystem::canonical(symlinkPath).string();
 
     // check to make sure the target really exists
-    if (!fs::is_regular_file(target + "/" + PNOR_TOC_FILE))
+    if (!std::filesystem::is_regular_file(target + "/" + PNOR_TOC_FILE))
     {
         return {};
     }
@@ -415,14 +415,14 @@
 {
     // The GARD partition is currently misspelled "GUARD." This file path will
     // need to be updated in the future.
-    auto path = fs::path(PNOR_PRSV_ACTIVE_PATH);
+    auto path = std::filesystem::path(PNOR_PRSV_ACTIVE_PATH);
     path /= "GUARD";
 
     utils::hiomapdSuspend(bus);
 
-    if (fs::is_regular_file(path))
+    if (std::filesystem::is_regular_file(path))
     {
-        fs::remove(path);
+        std::filesystem::remove(path);
     }
 
     utils::hiomapdResume(bus);
diff --git a/ubi/serialize.cpp b/ubi/serialize.cpp
index e047b87..2c31638 100644
--- a/ubi/serialize.cpp
+++ b/ubi/serialize.cpp
@@ -5,7 +5,7 @@
 #include <cereal/archives/json.hpp>
 #include <sdbusplus/server.hpp>
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <fstream>
 
 namespace openpower
@@ -15,15 +15,13 @@
 namespace updater
 {
 
-namespace fs = std::experimental::filesystem;
-
 void storeToFile(const std::string& versionId, uint8_t priority)
 {
     auto bus = sdbusplus::bus::new_default();
 
-    if (!fs::is_directory(PERSIST_DIR))
+    if (!std::filesystem::is_directory(PERSIST_DIR))
     {
-        fs::create_directories(PERSIST_DIR);
+        std::filesystem::create_directories(PERSIST_DIR);
     }
 
     // store one copy in /var/lib/obmc/openpower-pnor-code-mgmt/[versionId]
@@ -32,7 +30,7 @@
     cereal::JSONOutputArchive varArchive(varOutput);
     varArchive(cereal::make_nvp("priority", priority));
 
-    if (fs::is_directory(PNOR_RW_PREFIX + versionId))
+    if (std::filesystem::is_directory(PNOR_RW_PREFIX + versionId))
     {
         // store another copy in /media/pnor-rw-[versionId]/[versionId]
         auto rwPath = PNOR_RW_PREFIX + versionId + "/" + versionId;
@@ -53,7 +51,7 @@
 bool restoreFromFile(const std::string& versionId, uint8_t& priority)
 {
     auto varPath = PERSIST_DIR + versionId;
-    if (fs::exists(varPath))
+    if (std::filesystem::exists(varPath))
     {
         std::ifstream varInput(varPath.c_str(), std::ios::in);
         try
@@ -64,12 +62,12 @@
         }
         catch (cereal::RapidJSONException& e)
         {
-            fs::remove(varPath);
+            std::filesystem::remove(varPath);
         }
     }
 
     auto rwPath = PNOR_RW_PREFIX + versionId + "/" + versionId;
-    if (fs::exists(rwPath))
+    if (std::filesystem::exists(rwPath))
     {
         std::ifstream rwInput(rwPath.c_str(), std::ios::in);
         try
@@ -80,7 +78,7 @@
         }
         catch (cereal::RapidJSONException& e)
         {
-            fs::remove(rwPath);
+            std::filesystem::remove(rwPath);
         }
     }
 
@@ -88,7 +86,7 @@
     {
         std::string devicePath = "/dev/mtd/u-boot-env";
 
-        if (fs::exists(devicePath) && !devicePath.empty())
+        if (std::filesystem::exists(devicePath) && !devicePath.empty())
         {
             std::ifstream input(devicePath.c_str());
             std::string envVars;
@@ -130,9 +128,9 @@
     // so the file /media/pnor-rw-[versionId]/[versionId] will also be deleted
     // along with its surrounding directory.
     std::string path = PERSIST_DIR + versionId;
-    if (fs::exists(path))
+    if (std::filesystem::exists(path))
     {
-        fs::remove(path);
+        std::filesystem::remove(path);
     }
 }
 
diff --git a/ubi/watch.cpp b/ubi/watch.cpp
index fd2cad2..9cbed5d 100644
--- a/ubi/watch.cpp
+++ b/ubi/watch.cpp
@@ -11,7 +11,7 @@
 
 #include <cstddef>
 #include <cstring>
-#include <experimental/filesystem>
+#include <filesystem>
 #include <functional>
 #include <stdexcept>
 #include <string>
@@ -24,7 +24,6 @@
 {
 
 using namespace phosphor::logging;
-namespace fs = std::experimental::filesystem;
 
 Watch::Watch(sd_event* loop,
              std::function<void(const std::string&)> functionalCallback) :
@@ -33,9 +32,9 @@
 
 {
     // Create PNOR_ACTIVE_PATH if doesn't exist.
-    if (!fs::is_directory(PNOR_ACTIVE_PATH))
+    if (!std::filesystem::is_directory(PNOR_ACTIVE_PATH))
     {
-        fs::create_directories(PNOR_ACTIVE_PATH);
+        std::filesystem::create_directories(PNOR_ACTIVE_PATH);
     }
 
     wd = inotify_add_watch(fd(), PNOR_ACTIVE_PATH, IN_CREATE);
@@ -90,9 +89,9 @@
         auto event = reinterpret_cast<inotify_event*>(&buffer[offset]);
         // Update the functional association on a RO
         // active image symlink change
-        fs::path path(PNOR_ACTIVE_PATH);
+        std::filesystem::path path(PNOR_ACTIVE_PATH);
         path /= event->name;
-        if (fs::equivalent(path, PNOR_RO_ACTIVE_PATH))
+        if (std::filesystem::equivalent(path, PNOR_RO_ACTIVE_PATH))
         {
             auto id = ItemUpdaterUbi::determineId(path);
             static_cast<Watch*>(userdata)->functionalCallback(id);