c++17: drop experimental::filesystem

Use std::filesystem, and drop support for building with experimental
under c++14.

Tested: Build the repo.
Change-Id: I4af0d9c034dbfef5a65153ba5447b86c961aebf1
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/file.hpp b/file.hpp
index 34b1422..2819791 100644
--- a/file.hpp
+++ b/file.hpp
@@ -1,14 +1,12 @@
 #pragma once
 
 #include <stdio.h>
-#include <experimental/filesystem>
+#include <filesystem>
 namespace phosphor
 {
 namespace user
 {
 
-namespace fs = std::experimental::filesystem;
-
 /** @class File
  *  @brief Responsible for handling file pointer
  *  Needed by putspent(3)
@@ -71,9 +69,9 @@
         }
 
         // Needed for exception safety
-        if (removeOnExit && fs::exists(name))
+        if (removeOnExit && std::filesystem::exists(name))
         {
-            fs::remove(name);
+            std::filesystem::remove(name);
         }
     }
 
diff --git a/phosphor-ldap-config/Makefile.am b/phosphor-ldap-config/Makefile.am
index d6d8454..ba8980b 100644
--- a/phosphor-ldap-config/Makefile.am
+++ b/phosphor-ldap-config/Makefile.am
@@ -17,7 +17,6 @@
 phosphor_ldap_conf_LDFLAGS = $(SDBUSPLUS_LIBS) \
                              $(PHOSPHOR_DBUS_INTERFACES_LIBS) \
                              $(PHOSPHOR_LOGGING_LIBS) \
-                             -lstdc++fs \
                              -lldap
 
 phosphor_ldap_conf_CXXFLAGS = $(SYSTEMD_CFLAGS) \
diff --git a/phosphor-ldap-config/main.cpp b/phosphor-ldap-config/main.cpp
index 7f5cdad..4238086 100644
--- a/phosphor-ldap-config/main.cpp
+++ b/phosphor-ldap-config/main.cpp
@@ -1,6 +1,6 @@
 #include "config.h"
 #include "ldap_config_mgr.hpp"
-#include <experimental/filesystem>
+#include <filesystem>
 #include <phosphor-logging/log.hpp>
 #include <phosphor-logging/elog-errors.hpp>
 #include <sdbusplus/bus.hpp>
@@ -10,11 +10,13 @@
 {
     using namespace phosphor::logging;
     using namespace sdbusplus::xyz::openbmc_project::Common::Error;
-    namespace fs = std::experimental::filesystem;
-    fs::path configDir = fs::path(LDAP_CONFIG_FILE).parent_path();
 
-    if (!fs::exists(configDir / phosphor::ldap::defaultNslcdFile) ||
-        !fs::exists(configDir / phosphor::ldap::nsSwitchFile))
+    std::filesystem::path configDir =
+        std::filesystem::path(LDAP_CONFIG_FILE).parent_path();
+
+    if (!std::filesystem::exists(configDir /
+                                 phosphor::ldap::defaultNslcdFile) ||
+        !std::filesystem::exists(configDir / phosphor::ldap::nsSwitchFile))
     {
         log<level::ERR>("Error starting LDAP Config App, configfile(s) are "
                         "missing, exiting!!!");
diff --git a/phosphor-ldap-mapper/Makefile.am b/phosphor-ldap-mapper/Makefile.am
index 1c631e7..7bd58d5 100644
--- a/phosphor-ldap-mapper/Makefile.am
+++ b/phosphor-ldap-mapper/Makefile.am
@@ -12,8 +12,7 @@
 
 phosphor_ldap_mapper_LDFLAGS = $(SDBUSPLUS_LIBS) \
                                $(PHOSPHOR_DBUS_INTERFACES_LIBS) \
-                               $(PHOSPHOR_LOGGING_LIBS) \
-                               -lstdc++fs
+                               $(PHOSPHOR_LOGGING_LIBS)
 
 phosphor_ldap_mapper_CXXFLAGS = $(SYSTEMD_CFLAGS) \
                                 $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
diff --git a/phosphor-ldap-mapper/ldap_mapper_entry.cpp b/phosphor-ldap-mapper/ldap_mapper_entry.cpp
index 8410942..781833e 100644
--- a/phosphor-ldap-mapper/ldap_mapper_entry.cpp
+++ b/phosphor-ldap-mapper/ldap_mapper_entry.cpp
@@ -1,4 +1,4 @@
-#include <experimental/filesystem>
+#include <filesystem>
 #include <xyz/openbmc_project/Common/error.hpp>
 #include <xyz/openbmc_project/User/Common/error.hpp>
 #include <phosphor-logging/log.hpp>
@@ -25,8 +25,8 @@
                                  const std::string &privilege,
                                  LDAPMapperMgr &parent) :
     Ifaces(bus, path, true),
-    id(std::stol(std::experimental::filesystem::path(path).filename())),
-    manager(parent), persistPath(filePath)
+    id(std::stol(std::filesystem::path(path).filename())), manager(parent),
+    persistPath(filePath)
 {
     Ifaces::privilege(privilege, true);
     Ifaces::groupName(groupName, true);
@@ -36,8 +36,8 @@
 LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path,
                                  const char *filePath, LDAPMapperMgr &parent) :
     Ifaces(bus, path, true),
-    id(std::stol(std::experimental::filesystem::path(path).filename())),
-    manager(parent), persistPath(filePath)
+    id(std::stol(std::filesystem::path(path).filename())), manager(parent),
+    persistPath(filePath)
 {
 }
 
diff --git a/phosphor-ldap-mapper/ldap_mapper_mgr.cpp b/phosphor-ldap-mapper/ldap_mapper_mgr.cpp
index a1d6e11..b8d755b 100644
--- a/phosphor-ldap-mapper/ldap_mapper_mgr.cpp
+++ b/phosphor-ldap-mapper/ldap_mapper_mgr.cpp
@@ -1,3 +1,4 @@
+#include <filesystem>
 #include <xyz/openbmc_project/Common/error.hpp>
 #include <xyz/openbmc_project/User/Common/error.hpp>
 #include <phosphor-logging/log.hpp>
@@ -52,9 +53,9 @@
 void LDAPMapperMgr::deletePrivilegeMapper(Id id)
 {
     // Delete the persistent representation of the privilege mapper.
-    fs::path mapperPath(persistPath);
+    std::filesystem::path mapperPath(persistPath);
     mapperPath /= std::to_string(id);
-    fs::remove(mapperPath);
+    std::filesystem::remove(mapperPath);
 
     PrivilegeMapperList.erase(id);
 }
@@ -97,15 +98,13 @@
 
 void LDAPMapperMgr::restore()
 {
-    namespace fs = std::experimental::filesystem;
-
-    fs::path dir(persistPath);
-    if (!fs::exists(dir) || fs::is_empty(dir))
+    std::filesystem::path dir(persistPath);
+    if (!std::filesystem::exists(dir) || std::filesystem::is_empty(dir))
     {
         return;
     }
 
-    for (auto &file : fs::directory_iterator(dir))
+    for (auto &file : std::filesystem::directory_iterator(dir))
     {
         std::string id = file.path().filename().c_str();
         size_t idNum = std::stol(id);
diff --git a/phosphor-ldap-mapper/ldap_mapper_serialize.cpp b/phosphor-ldap-mapper/ldap_mapper_serialize.cpp
index 3ef809e..65918fd 100644
--- a/phosphor-ldap-mapper/ldap_mapper_serialize.cpp
+++ b/phosphor-ldap-mapper/ldap_mapper_serialize.cpp
@@ -1,6 +1,7 @@
 #include <cereal/archives/binary.hpp>
 #include <cereal/types/string.hpp>
 #include <fstream>
+#include <filesystem>
 #include <phosphor-logging/log.hpp>
 #include "config.h"
 #include "ldap_mapper_serialize.hpp"
@@ -54,7 +55,8 @@
         privilege(privilege, true);
 }
 
-fs::path serialize(const LDAPMapperEntry& entry, Id id, const fs::path& dir)
+std::filesystem::path serialize(const LDAPMapperEntry& entry, Id id,
+                                const std::filesystem::path& dir)
 {
     auto path = dir / std::to_string(id);
     std::ofstream os(path.c_str(), std::ios::binary);
@@ -63,11 +65,11 @@
     return path;
 }
 
-bool deserialize(const fs::path& path, LDAPMapperEntry& entry)
+bool deserialize(const std::filesystem::path& path, LDAPMapperEntry& entry)
 {
     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);
@@ -79,13 +81,13 @@
     catch (cereal::Exception& e)
     {
         log<level::ERR>(e.what());
-        fs::remove(path);
+        std::filesystem::remove(path);
         return false;
     }
     catch (const std::length_error& e)
     {
         log<level::ERR>(e.what());
-        fs::remove(path);
+        std::filesystem::remove(path);
         return false;
     }
 }
diff --git a/phosphor-ldap-mapper/ldap_mapper_serialize.hpp b/phosphor-ldap-mapper/ldap_mapper_serialize.hpp
index 5ab71c0..7d918d8 100644
--- a/phosphor-ldap-mapper/ldap_mapper_serialize.hpp
+++ b/phosphor-ldap-mapper/ldap_mapper_serialize.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include "config.h"
 #include "ldap_mapper_entry.hpp"
 
@@ -9,8 +9,6 @@
 namespace user
 {
 
-namespace fs = std::experimental::filesystem;
-
 /** @brief Serialize and persist LDAP privilege mapper D-Bus object
  *
  *  @param[in] entry - LDAP privilege mapper entry
@@ -18,9 +16,10 @@
  *  @param[in] dir - pathname of directory where the serialized privilege
  *                   mappings are stored.
  *
- *  @return fs::path - pathname of persisted error file
+ *  @return std::filesystem::path - pathname of persisted error file
  */
-fs::path serialize(const LDAPMapperEntry& entry, Id id, const fs::path& dir);
+std::filesystem::path serialize(const LDAPMapperEntry& entry, Id id,
+                                const std::filesystem::path& dir);
 
 /** @brief Deserialize a persisted LDAP privilege mapper into a D-Bus object
  *
@@ -30,7 +29,7 @@
  *
  *  @return bool - true if the deserialization was successful, false otherwise.
  */
-bool deserialize(const fs::path& path, LDAPMapperEntry& entry);
+bool deserialize(const std::filesystem::path& path, LDAPMapperEntry& entry);
 
 } // namespace user
 } // namespace phosphor
diff --git a/phosphor-ldap-mapper/main.cpp b/phosphor-ldap-mapper/main.cpp
index e0d2255..1833a6a 100644
--- a/phosphor-ldap-mapper/main.cpp
+++ b/phosphor-ldap-mapper/main.cpp
@@ -1,5 +1,5 @@
 #include <string>
-#include <experimental/filesystem>
+#include <filesystem>
 #include "config.h"
 #include "ldap_mapper_mgr.hpp"
 
@@ -13,7 +13,7 @@
                                             LDAP_MAPPER_PERSIST_PATH);
 
     // Create a directory to persist errors.
-    std::experimental::filesystem::create_directories(LDAP_MAPPER_PERSIST_PATH);
+    std::filesystem::create_directories(LDAP_MAPPER_PERSIST_PATH);
 
     // Restore the serialized LDAP group privilege mapping.
     mapperMgr.restore();
diff --git a/test/Makefile.am b/test/Makefile.am
index fc6b72e..03c918e 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -18,8 +18,7 @@
           $(PHOSPHOR_DBUS_INTERFACES_LIBS) \
           $(PHOSPHOR_LOGGING_LIBS) \
           $(SDBUSPLUS_LIBS) \
-          -lcrypt \
-          -lstdc++fs
+          -lcrypt
 
 check_PROGRAMS = ldap_config_test
 ldap_config_test_CPPFLAGS = $(cppflags)
diff --git a/test/ldap_mapper_test.cpp b/test/ldap_mapper_test.cpp
index b3c1a4f..a044b64 100644
--- a/test/ldap_mapper_test.cpp
+++ b/test/ldap_mapper_test.cpp
@@ -1,5 +1,5 @@
 #include <gtest/gtest.h>
-#include <experimental/filesystem>
+#include <filesystem>
 #include <stdlib.h>
 #include <sdbusplus/bus.hpp>
 #include "phosphor-ldap-mapper/ldap_mapper_entry.hpp"
@@ -15,8 +15,6 @@
 namespace user
 {
 
-namespace fs = std::experimental::filesystem;
-
 class TestSerialization : public testing::Test
 {
   public:
@@ -29,15 +27,15 @@
     void SetUp() override
     {
         char tempDir[] = "/tmp/privmapper_test.XXXXXX";
-        dir = fs::path(mkdtemp(tempDir));
+        dir = std::filesystem::path(mkdtemp(tempDir));
     }
 
     void TearDown() override
     {
-        fs::remove_all(dir);
+        std::filesystem::remove_all(dir);
     }
 
-    fs::path dir;
+    std::filesystem::path dir;
     sdbusplus::bus::bus bus;
 };
 
@@ -84,19 +82,20 @@
 {
     std::string groupName = "admin";
     std::string privilege = "priv-admin";
-    namespace fs = std::experimental::filesystem;
     size_t entryId = 1;
     LDAPMapperMgr manager1(TestSerialization::bus, mapperMgrRoot,
                            (TestSerialization::dir).c_str());
     EXPECT_NO_THROW(manager1.create(groupName, privilege));
 
-    EXPECT_EQ(fs::exists(TestSerialization::dir / std::to_string(entryId)),
+    EXPECT_EQ(std::filesystem::exists(TestSerialization::dir /
+                                      std::to_string(entryId)),
               true);
     LDAPMapperMgr manager2(TestSerialization::bus, mapperMgrRoot,
                            (TestSerialization::dir).c_str());
     EXPECT_NO_THROW(manager2.restore());
     EXPECT_NO_THROW(manager2.deletePrivilegeMapper(entryId));
-    EXPECT_EQ(fs::exists(TestSerialization::dir / std::to_string(entryId)),
+    EXPECT_EQ(std::filesystem::exists(TestSerialization::dir /
+                                      std::to_string(entryId)),
               false);
 }
 
diff --git a/users.cpp b/users.cpp
index 562a0ad..1dbe85a 100644
--- a/users.cpp
+++ b/users.cpp
@@ -14,6 +14,7 @@
 // limitations under the License.
 */
 
+#include <filesystem>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -56,8 +57,7 @@
              std::vector<std::string> groups, std::string priv, bool enabled,
              UserMgr &parent) :
     Interfaces(bus, path, true),
-    userName(std::experimental::filesystem::path(path).filename()),
-    manager(parent)
+    userName(std::filesystem::path(path).filename()), manager(parent)
 {
     UsersIface::userPrivilege(priv, true);
     UsersIface::userGroups(groups, true);
diff --git a/users.hpp b/users.hpp
index 45d86cd..a13825b 100644
--- a/users.hpp
+++ b/users.hpp
@@ -14,7 +14,6 @@
 // limitations under the License.
 */
 #pragma once
-#include <experimental/filesystem>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/object.hpp>
 #include <xyz/openbmc_project/User/Attributes/server.hpp>