c++17: drop experimental::filesystem

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

Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Change-Id: I730c0d6dce53b5e0aa0867cddb7f325cdb9b45fc
diff --git a/bmc_dump_entry.cpp b/bmc_dump_entry.cpp
index ce59a7f..20610c7 100644
--- a/bmc_dump_entry.cpp
+++ b/bmc_dump_entry.cpp
@@ -18,9 +18,9 @@
     // Delete Dump file from Permanent location
     try
     {
-        fs::remove_all(file.parent_path());
+        std::filesystem::remove_all(file.parent_path());
     }
-    catch (fs::filesystem_error& e)
+    catch (std::filesystem::filesystem_error& e)
     {
         // Log Error message and continue
         log<level::ERR>(e.what());
diff --git a/bmc_dump_entry.hpp b/bmc_dump_entry.hpp
index da63b25..f227641 100644
--- a/bmc_dump_entry.hpp
+++ b/bmc_dump_entry.hpp
@@ -22,8 +22,6 @@
 using EntryIfaces = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::Dump::Entry::server::BMC>;
 
-namespace fs = std::experimental::filesystem;
-
 class Manager;
 
 /** @class Entry
@@ -53,7 +51,8 @@
      *  @param[in] parent - The dump entry's parent.
      */
     Entry(sdbusplus::bus::bus& bus, const std::string& objPath, uint32_t dumpId,
-          uint64_t timeStamp, uint64_t fileSize, const fs::path& file,
+          uint64_t timeStamp, uint64_t fileSize,
+          const std::filesystem::path& file,
           phosphor::dump::OperationStatus status,
           phosphor::dump::Manager& parent) :
         EntryIfaces(bus, objPath.c_str(), true),
@@ -81,7 +80,8 @@
      *  @param[in] fileSize - Dump file size in bytes.
      *  @param[in] file - Name of dump file.
      */
-    void update(uint64_t timeStamp, uint64_t fileSize, const fs::path& filePath)
+    void update(uint64_t timeStamp, uint64_t fileSize,
+                const std::filesystem::path& filePath)
     {
         elapsed(timeStamp);
         size(fileSize);
@@ -95,7 +95,7 @@
 
   private:
     /** @Dump file name */
-    fs::path file;
+    std::filesystem::path file;
 };
 
 } // namespace bmc
diff --git a/core_manager.cpp b/core_manager.cpp
index 19b80a2..9dfaa9b 100644
--- a/core_manager.cpp
+++ b/core_manager.cpp
@@ -2,7 +2,7 @@
 
 #include "core_manager.hpp"
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <phosphor-logging/log.hpp>
 #include <regex>
 #include <sdbusplus/exception.hpp>
@@ -23,8 +23,7 @@
 
     for (const auto& i : fileInfo)
     {
-        namespace fs = std::experimental::filesystem;
-        fs::path file(i.first);
+        std::filesystem::path file(i.first);
         std::string name = file.filename();
 
         /*
diff --git a/dump-extensions/openpower-dumps/dump_manager_resource.cpp b/dump-extensions/openpower-dumps/dump_manager_resource.cpp
index 76580ee..50c7f59 100644
--- a/dump-extensions/openpower-dumps/dump_manager_resource.cpp
+++ b/dump-extensions/openpower-dumps/dump_manager_resource.cpp
@@ -46,7 +46,7 @@
     // Get the id
     auto id = lastEntryId + 1;
     auto idString = std::to_string(id);
-    auto objPath = fs::path(baseEntryPath) / idString;
+    auto objPath = std::filesystem::path(baseEntryPath) / idString;
 
     try
     {
@@ -89,7 +89,7 @@
 
     auto id = lastEntryId + 1;
     auto idString = std::to_string(id);
-    auto objPath = fs::path(baseEntryPath) / idString;
+    auto objPath = std::filesystem::path(baseEntryPath) / idString;
     std::time_t timeStamp = std::time(nullptr);
 
     std::string vspString = params[sdbusplus::com::ibm::Dump::server::Create::
diff --git a/dump-extensions/openpower-dumps/dump_manager_system.cpp b/dump-extensions/openpower-dumps/dump_manager_system.cpp
index d7b73a9..4652261 100644
--- a/dump-extensions/openpower-dumps/dump_manager_system.cpp
+++ b/dump-extensions/openpower-dumps/dump_manager_system.cpp
@@ -45,7 +45,7 @@
     // Get the id
     auto id = lastEntryId + 1;
     auto idString = std::to_string(id);
-    auto objPath = fs::path(baseEntryPath) / idString;
+    auto objPath = std::filesystem::path(baseEntryPath) / idString;
 
     try
     {
@@ -102,7 +102,7 @@
 
     auto id = lastEntryId + 1;
     auto idString = std::to_string(id);
-    auto objPath = fs::path(baseEntryPath) / idString;
+    auto objPath = std::filesystem::path(baseEntryPath) / idString;
     std::time_t timeStamp = std::time(nullptr);
 
     try
diff --git a/dump-extensions/openpower-dumps/resource_dump_entry.hpp b/dump-extensions/openpower-dumps/resource_dump_entry.hpp
index 3e099a9..c68d90a 100644
--- a/dump-extensions/openpower-dumps/resource_dump_entry.hpp
+++ b/dump-extensions/openpower-dumps/resource_dump_entry.hpp
@@ -19,8 +19,6 @@
 using EntryIfaces = sdbusplus::server::object::object<
     sdbusplus::com::ibm::Dump::Entry::server::Resource>;
 
-namespace fs = std::experimental::filesystem;
-
 class Manager;
 
 /** @class Entry
diff --git a/dump-extensions/openpower-dumps/system_dump_entry.hpp b/dump-extensions/openpower-dumps/system_dump_entry.hpp
index 821be37..7cf07c6 100644
--- a/dump-extensions/openpower-dumps/system_dump_entry.hpp
+++ b/dump-extensions/openpower-dumps/system_dump_entry.hpp
@@ -18,8 +18,6 @@
 using EntryIfaces = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::Dump::Entry::server::System>;
 
-namespace fs = std::experimental::filesystem;
-
 class Manager;
 
 /** @class Entry
diff --git a/dump_entry.hpp b/dump_entry.hpp
index 5fd3256..98502b4 100644
--- a/dump_entry.hpp
+++ b/dump_entry.hpp
@@ -5,7 +5,7 @@
 #include "xyz/openbmc_project/Object/Delete/server.hpp"
 #include "xyz/openbmc_project/Time/EpochTime/server.hpp"
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/object.hpp>
 
@@ -29,7 +29,6 @@
 
 using OperationStatus =
     sdbusplus::xyz::openbmc_project::Common::server::Progress::OperationStatus;
-namespace fs = std::experimental::filesystem;
 
 class Manager;
 
diff --git a/dump_manager_bmc.cpp b/dump_manager_bmc.cpp
index aef7a3e..4ffcd14 100644
--- a/dump_manager_bmc.cpp
+++ b/dump_manager_bmc.cpp
@@ -46,7 +46,7 @@
     auto id = captureDump(Type::UserRequested, paths);
 
     // Entry Object path.
-    auto objPath = fs::path(baseEntryPath) / std::to_string(id);
+    auto objPath = std::filesystem::path(baseEntryPath) / std::to_string(id);
 
     try
     {
@@ -78,7 +78,7 @@
 
     if (pid == 0)
     {
-        fs::path dumpPath(dumpDir);
+        std::filesystem::path dumpPath(dumpDir);
         auto id = std::to_string(lastEntryId + 1);
         dumpPath /= id;
 
@@ -118,7 +118,7 @@
     return ++lastEntryId;
 }
 
-void Manager::createEntry(const fs::path& file)
+void Manager::createEntry(const std::filesystem::path& file)
 {
     // Dump File Name format obmcdump_ID_EPOCHTIME.EXT
     static constexpr auto ID_POS = 1;
@@ -145,20 +145,20 @@
     if (dumpEntry != entries.end())
     {
         dynamic_cast<phosphor::dump::bmc::Entry*>(dumpEntry->second.get())
-            ->update(stoull(msString), fs::file_size(file), file);
+            ->update(stoull(msString), std::filesystem::file_size(file), file);
         return;
     }
 
     // Entry Object path.
-    auto objPath = fs::path(baseEntryPath) / std::to_string(id);
+    auto objPath = std::filesystem::path(baseEntryPath) / std::to_string(id);
 
     try
     {
         entries.insert(std::make_pair(
-            id,
-            std::make_unique<bmc::Entry>(
-                bus, objPath.c_str(), id, stoull(msString), fs::file_size(file),
-                file, phosphor::dump::OperationStatus::Completed, *this)));
+            id, std::make_unique<bmc::Entry>(
+                    bus, objPath.c_str(), id, stoull(msString),
+                    std::filesystem::file_size(file), file,
+                    phosphor::dump::OperationStatus::Completed, *this)));
     }
     catch (const std::invalid_argument& e)
     {
@@ -167,7 +167,7 @@
                         entry("OBJECTPATH=%s", objPath.c_str()),
                         entry("ID=%d", id),
                         entry("TIMESTAMP=%ull", stoull(msString)),
-                        entry("SIZE=%d", fs::file_size(file)),
+                        entry("SIZE=%d", std::filesystem::file_size(file)),
                         entry("FILENAME=%s", file.c_str()));
         return;
     }
@@ -186,7 +186,8 @@
             createEntry(i.first);
         }
         // Start inotify watch on newly created directory.
-        else if ((IN_CREATE == i.second) && fs::is_directory(i.first))
+        else if ((IN_CREATE == i.second) &&
+                 std::filesystem::is_directory(i.first))
         {
             auto watchObj = std::make_unique<Watch>(
                 eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE, EPOLLIN, i.first,
@@ -199,7 +200,7 @@
     }
 }
 
-void Manager::removeWatch(const fs::path& path)
+void Manager::removeWatch(const std::filesystem::path& path)
 {
     // Delete Watch entry from map.
     childWatchMap.erase(path);
@@ -207,27 +208,27 @@
 
 void Manager::restore()
 {
-    fs::path dir(dumpDir);
-    if (!fs::exists(dir) || fs::is_empty(dir))
+    std::filesystem::path dir(dumpDir);
+    if (!std::filesystem::exists(dir) || std::filesystem::is_empty(dir))
     {
         return;
     }
 
     // Dump file path: <DUMP_PATH>/<id>/<filename>
-    for (const auto& p : fs::directory_iterator(dir))
+    for (const auto& p : std::filesystem::directory_iterator(dir))
     {
         auto idStr = p.path().filename().string();
 
         // Consider only directory's with dump id as name.
         // Note: As per design one file per directory.
-        if ((fs::is_directory(p.path())) &&
+        if ((std::filesystem::is_directory(p.path())) &&
             std::all_of(idStr.begin(), idStr.end(), ::isdigit))
         {
             lastEntryId =
                 std::max(lastEntryId, static_cast<uint32_t>(std::stoul(idStr)));
-            auto fileIt = fs::directory_iterator(p.path());
+            auto fileIt = std::filesystem::directory_iterator(p.path());
             // Create dump entry d-bus object.
-            if (fileIt != fs::end(fileIt))
+            if (fileIt != std::filesystem::end(fileIt))
             {
                 createEntry(fileIt->path());
             }
@@ -243,11 +244,11 @@
     auto size = 0;
 
     // Get current size of the dump directory.
-    for (const auto& p : fs::recursive_directory_iterator(dumpDir))
+    for (const auto& p : std::filesystem::recursive_directory_iterator(dumpDir))
     {
-        if (!fs::is_directory(p))
+        if (!std::filesystem::is_directory(p))
         {
-            size += fs::file_size(p);
+            size += std::filesystem::file_size(p);
         }
     }
 
diff --git a/dump_manager_bmc.hpp b/dump_manager_bmc.hpp
index 24cfd0c..762f945 100644
--- a/dump_manager_bmc.hpp
+++ b/dump_manager_bmc.hpp
@@ -5,7 +5,7 @@
 #include "watch.hpp"
 #include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <xyz/openbmc_project/Dump/Create/server.hpp>
 
 namespace phosphor
@@ -29,8 +29,6 @@
 using Type =
     sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type;
 
-namespace fs = std::experimental::filesystem;
-
 using Watch = phosphor::dump::inotify::Watch;
 
 // Type to dreport type  string map
@@ -101,7 +99,7 @@
     /** @brief Create Dump entry d-bus object
      *  @param[in] fullPath - Full path of the Dump file name
      */
-    void createEntry(const fs::path& fullPath);
+    void createEntry(const std::filesystem::path& fullPath);
 
     /**  @brief Capture BMC Dump based on the Dump type.
      *  @param[in] type - Type of the Dump.
@@ -129,7 +127,7 @@
      *        watch map and associated entry from the map.
      *        @param[in] path - unique identifier of the map
      */
-    void removeWatch(const fs::path& path);
+    void removeWatch(const std::filesystem::path& path);
 
     /** @brief Calculate per dump allowed size based on the available
      *        size in the dump location.
@@ -149,7 +147,7 @@
     /** @brief Child directory path and its associated watch object map
      *        [path:watch object]
      */
-    std::map<fs::path, std::unique_ptr<Watch>> childWatchMap;
+    std::map<std::filesystem::path, std::unique_ptr<Watch>> childWatchMap;
 };
 
 } // namespace bmc
diff --git a/dump_offload.cpp b/dump_offload.cpp
index 18e3bb6..8089d75 100644
--- a/dump_offload.cpp
+++ b/dump_offload.cpp
@@ -128,7 +128,8 @@
     return unixSocket;
 }
 
-void requestOffload(fs::path file, uint32_t dumpId, std::string writePath)
+void requestOffload(std::filesystem::path file, uint32_t dumpId,
+                    std::string writePath)
 {
     using namespace sdbusplus::xyz::openbmc_project::Common::File::Error;
     using ErrnoOpen = xyz::openbmc_project::Common::File::Open::ERRNO;
@@ -136,7 +137,7 @@
     using ErrnoWrite = xyz::openbmc_project::Common::File::Write::ERRNO;
     using PathWrite = xyz::openbmc_project::Common::File::Write::PATH;
     // open a dump file for a transfer.
-    fs::path dumpPath(BMC_DUMP_PATH);
+    std::filesystem::path dumpPath(BMC_DUMP_PATH);
     dumpPath /= std::to_string(dumpId);
     dumpPath /= file.filename();
 
diff --git a/dump_offload.hpp b/dump_offload.hpp
index 2678061..8e10771 100644
--- a/dump_offload.hpp
+++ b/dump_offload.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#include <experimental/filesystem>
+#include <filesystem>
 
 namespace phosphor
 {
@@ -9,8 +9,6 @@
 namespace offload
 {
 
-namespace fs = std::experimental::filesystem;
-
 /**
  * @brief Kicks off the instructions to
  *        start offload of the dump using dbus
@@ -20,7 +18,8 @@
  * @param[in] writePath[in] - path to write the dump file.
  *
  **/
-void requestOffload(fs::path file, uint32_t dumpId, std::string writePath);
+void requestOffload(std::filesystem::path file, uint32_t dumpId,
+                    std::string writePath);
 
 } // namespace offload
 } // namespace dump
diff --git a/dump_serialize.cpp b/dump_serialize.cpp
index 799b142..89c74c8 100644
--- a/dump_serialize.cpp
+++ b/dump_serialize.cpp
@@ -14,18 +14,18 @@
 
 using namespace phosphor::logging;
 
-void serialize(const ElogList& list, const fs::path& dir)
+void serialize(const ElogList& list, const std::filesystem::path& dir)
 {
     std::ofstream os(dir.c_str(), std::ios::binary);
     cereal::BinaryOutputArchive oarchive(os);
     oarchive(list);
 }
 
-bool deserialize(const fs::path& path, ElogList& list)
+bool deserialize(const std::filesystem::path& path, ElogList& list)
 {
     try
     {
-        if (fs::exists(path))
+        if (std::filesystem::exists(path))
         {
             std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
             cereal::BinaryInputArchive iarchive(is);
@@ -37,7 +37,7 @@
     catch (cereal::Exception& e)
     {
         log<level::ERR>(e.what());
-        fs::remove(path);
+        std::filesystem::remove(path);
         return false;
     }
 }
diff --git a/dump_serialize.hpp b/dump_serialize.hpp
index 8ad4a24..8fc4d14 100644
--- a/dump_serialize.hpp
+++ b/dump_serialize.hpp
@@ -2,7 +2,7 @@
 
 #include "config.h"
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <set>
 
 namespace phosphor
@@ -14,22 +14,21 @@
 using EId = uint32_t;
 using ElogList = std::set<EId>;
 
-namespace fs = std::experimental::filesystem;
-
 /** @brief Serialize and persist list of ids.
  *  @param[in] list - elog id list.
  *  @param[in] dir - pathname of file where the serialized elog id's will
  *                   be placed.
  */
 void serialize(const ElogList& list,
-               const fs::path& dir = fs::path(ELOG_ID_PERSIST_PATH));
+               const std::filesystem::path& dir =
+                   std::filesystem::path(ELOG_ID_PERSIST_PATH));
 
 /** @brief Deserialze a persisted list of ids into list
  *  @param[in] path - pathname of persisted error file
  *  @param[out] list - elog id list
  *  @return bool - true if the deserialization was successful, false otherwise.
  */
-bool deserialize(const fs::path& path, ElogList& list);
+bool deserialize(const std::filesystem::path& path, ElogList& list);
 
 } // namespace elog
 } // namespace dump
diff --git a/elog_watch.cpp b/elog_watch.cpp
index ed26fd5..6b92dee 100644
--- a/elog_watch.cpp
+++ b/elog_watch.cpp
@@ -45,8 +45,8 @@
                        std::placeholders::_1))
 {
 
-    fs::path file(ELOG_ID_PERSIST_PATH);
-    if (fs::exists(file))
+    std::filesystem::path file(ELOG_ID_PERSIST_PATH);
+    if (std::filesystem::exists(file))
     {
         if (!deserialize(ELOG_ID_PERSIST_PATH, elogList))
         {
diff --git a/elog_watch.hpp b/elog_watch.hpp
index 3b345b5..b04c54c 100644
--- a/elog_watch.hpp
+++ b/elog_watch.hpp
@@ -5,6 +5,7 @@
 #include "dump_manager_bmc.hpp"
 
 #include <cereal/access.hpp>
+#include <filesystem>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server.hpp>
 #include <set>
@@ -78,7 +79,7 @@
      */
     inline EId getEid(const std::string& objectPath)
     {
-        fs::path path(objectPath);
+        std::filesystem::path path(objectPath);
         return std::stoul(path.filename());
     }
 
diff --git a/watch.cpp b/watch.cpp
index 659320a..137ff76 100644
--- a/watch.cpp
+++ b/watch.cpp
@@ -24,13 +24,14 @@
 }
 
 Watch::Watch(const EventPtr& eventObj, const int flags, const uint32_t mask,
-             const uint32_t events, const fs::path& path, UserType userFunc) :
+             const uint32_t events, const std::filesystem::path& path,
+             UserType userFunc) :
     flags(flags),
     mask(mask), events(events), path(path), fd(inotifyInit()),
     userFunc(userFunc)
 {
     // Check if watch DIR exists.
-    if (!fs::is_directory(path))
+    if (!std::filesystem::is_directory(path))
     {
         log<level::ERR>("Watch directory doesn't exist",
                         entry("DIR=%s", path.c_str()));
diff --git a/watch.hpp b/watch.hpp
index 5452b20..a9ec18e 100644
--- a/watch.hpp
+++ b/watch.hpp
@@ -5,7 +5,7 @@
 #include <sys/inotify.h>
 #include <systemd/sd-event.h>
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <functional>
 #include <map>
 
@@ -16,10 +16,8 @@
 namespace inotify
 {
 
-namespace fs = std::experimental::filesystem;
-
 // User specific call back function input map(path:event) type.
-using UserMap = std::map<fs::path, uint32_t>;
+using UserMap = std::map<std::filesystem::path, uint32_t>;
 
 // User specific callback function wrapper type.
 using UserType = std::function<void(const UserMap&)>;
@@ -46,7 +44,7 @@
      *
      */
     Watch(const EventPtr& eventObj, int flags, uint32_t mask, uint32_t events,
-          const fs::path& path, UserType userFunc);
+          const std::filesystem::path& path, UserType userFunc);
 
     Watch(const Watch&) = delete;
     Watch& operator=(const Watch&) = delete;
@@ -84,7 +82,7 @@
     uint32_t events;
 
     /** @brief File path to be watched */
-    fs::path path;
+    std::filesystem::path path;
 
     /** @brief dump file directory watch descriptor */
     int wd = -1;