Replace std::experimental::filesystem with std::filesystem

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I91d2f1b7a8858ba8c676b68693863bb35b56dffc
diff --git a/i2c_occ.cpp b/i2c_occ.cpp
index 1c1a9ff..a9d55fe 100644
--- a/i2c_occ.cpp
+++ b/i2c_occ.cpp
@@ -11,7 +11,7 @@
 namespace i2c_occ
 {
 
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
 
 // The occ_master sysfs file
 constexpr auto OCC_MASTER_FILE = "occ_master";
@@ -26,7 +26,7 @@
 
 static bool isMasterOcc(const fs::directory_entry& p)
 {
-    auto f = p / OCC_MASTER_FILE;
+    auto f = p / fs::path{OCC_MASTER_FILE};
     auto str = getFileContent(f);
     return (!str.empty()) && (str[0] == '1');
 }
@@ -52,7 +52,7 @@
         for (auto& p : fs::directory_iterator(path))
         {
             // Check if a device's name is "p8-occ-hwmon"
-            auto f = p / "name";
+            auto f = p / fs::path{"name"};
             auto str = getFileContent(f);
             if (str == I2C_OCC_DEVICE_NAME)
             {
diff --git a/i2c_occ.hpp b/i2c_occ.hpp
index 3635ea1..9ef814b 100644
--- a/i2c_occ.hpp
+++ b/i2c_occ.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <vector>
 
 #ifdef I2C_OCC
@@ -8,7 +8,7 @@
 namespace i2c_occ
 {
 
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
 
 /** @brief Get file content
  *
diff --git a/occ_device.cpp b/occ_device.cpp
index 6cd6a1f..2ee5f34 100644
--- a/occ_device.cpp
+++ b/occ_device.cpp
@@ -15,15 +15,14 @@
 std::string Device::getPathBack(const fs::path& path)
 {
     if (path.empty())
+    {
         return std::string();
+    }
 
     // Points to the last element in the path
     auto conf = --path.end();
 
-    // The last element will be '.' if the path ends in '/'
-    // This behavior differs between filesystem and experimental::filesystem
-    // Verify there is an element before too
-    if (!conf->compare(".") && conf != path.begin())
+    if (conf->empty() && conf != path.begin())
     {
         return *(--conf);
     }
diff --git a/occ_device.hpp b/occ_device.hpp
index 4215640..a877c8c 100644
--- a/occ_device.hpp
+++ b/occ_device.hpp
@@ -8,7 +8,7 @@
 
 #include <org/open_power/OCC/Device/error.hpp>
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <fstream>
 
 namespace open_power
@@ -18,7 +18,7 @@
 
 class Manager;
 class Status;
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
 using namespace sdbusplus::org::open_power::OCC::Device::Error;
 
 /** @class Device
diff --git a/occ_errors.hpp b/occ_errors.hpp
index f623704..3b00e94 100644
--- a/occ_errors.hpp
+++ b/occ_errors.hpp
@@ -6,14 +6,14 @@
 
 #include <unistd.h>
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <functional>
 namespace open_power
 {
 namespace occ
 {
 
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
 
 /** @class Error
  *  @brief Monitors for OCC device error condition
diff --git a/occ_manager.cpp b/occ_manager.cpp
index 6191a75..f53ce52 100644
--- a/occ_manager.cpp
+++ b/occ_manager.cpp
@@ -12,7 +12,7 @@
 
 #include <chrono>
 #include <cmath>
-#include <experimental/filesystem>
+#include <filesystem>
 #include <regex>
 
 namespace open_power
@@ -112,7 +112,7 @@
 
 int Manager::cpuCreated(sdbusplus::message::message& msg)
 {
-    namespace fs = std::experimental::filesystem;
+    namespace fs = std::filesystem;
 
     sdbusplus::message::object_path o;
     msg.read(o);
diff --git a/powercap.cpp b/powercap.cpp
index ccf2998..26c1ee7 100644
--- a/powercap.cpp
+++ b/powercap.cpp
@@ -22,7 +22,7 @@
 constexpr auto POWER_CAP_ENABLE_PROP = "PowerCapEnable";
 
 using namespace phosphor::logging;
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
 
 uint32_t PowerCap::getOccInput(uint32_t pcap, bool pcapEnabled)
 {
diff --git a/powercap.hpp b/powercap.hpp
index 212c1c2..58070ba 100644
--- a/powercap.hpp
+++ b/powercap.hpp
@@ -8,7 +8,7 @@
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/bus/match.hpp>
 
-#include <experimental/filesystem>
+#include <filesystem>
 
 namespace open_power
 {
@@ -99,8 +99,7 @@
      *
      * @return std::string - The filename, or empty string if not found.
      */
-    std::string
-        getPcapFilename(const std::experimental::filesystem::path& path);
+    std::string getPcapFilename(const std::filesystem::path& path);
 
     /** @brief The master occ name */
     std::string occMasterName;
diff --git a/powermode.hpp b/powermode.hpp
index ddb1072..60befce 100644
--- a/powermode.hpp
+++ b/powermode.hpp
@@ -8,7 +8,7 @@
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/bus/match.hpp>
 
-#include <experimental/filesystem>
+#include <filesystem>
 
 namespace open_power
 {
diff --git a/test/TestI2cOcc.cpp b/test/TestI2cOcc.cpp
index 92028fd..c0fe979 100644
--- a/test/TestI2cOcc.cpp
+++ b/test/TestI2cOcc.cpp
@@ -1,6 +1,6 @@
 #include "i2c_occ.hpp"
 
-#include <experimental/filesystem>
+#include <filesystem>
 #include <fstream>
 #include <string>
 
@@ -10,7 +10,7 @@
 namespace i2c_occ
 {
 
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
 
 using namespace std::string_literals;
 const auto STR_4_0050 = "4-0050"s;
diff --git a/test/error_files_tests.cpp b/test/error_files_tests.cpp
index c412e63..6931cdc 100644
--- a/test/error_files_tests.cpp
+++ b/test/error_files_tests.cpp
@@ -17,7 +17,7 @@
 constexpr auto legacyErrorTemp = "occ_dvfs_ot";
 constexpr auto noError = "0";
 
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
 using namespace open_power::occ;
 
 class ErrorFiles : public ::testing::Test
diff --git a/test/utest.cpp b/test/utest.cpp
index 2933023..05c8f71 100644
--- a/test/utest.cpp
+++ b/test/utest.cpp
@@ -4,7 +4,7 @@
 #include <occ_events.hpp>
 #include <occ_manager.hpp>
 
-#include <experimental/filesystem>
+#include <filesystem>
 
 #include <gtest/gtest.h>
 
@@ -47,7 +47,7 @@
 
 TEST(VerifyPathParsing, EmptyPath)
 {
-    std::experimental::filesystem::path path = "";
+    std::filesystem::path path = "";
     std::string parsed = Device::getPathBack(path);
 
     EXPECT_STREQ(parsed.c_str(), "");
@@ -55,7 +55,7 @@
 
 TEST(VerifyPathParsing, FilenamePath)
 {
-    std::experimental::filesystem::path path = "/test/foo.bar";
+    std::filesystem::path path = "/test/foo.bar";
     std::string parsed = Device::getPathBack(path);
 
     EXPECT_STREQ(parsed.c_str(), "foo.bar");
@@ -63,7 +63,7 @@
 
 TEST(VerifyPathParsing, DirectoryPath)
 {
-    std::experimental::filesystem::path path = "/test/bar/";
+    std::filesystem::path path = "/test/bar/";
     std::string parsed = Device::getPathBack(path);
 
     EXPECT_STREQ(parsed.c_str(), "bar");