]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test,tool: include <filesystem> if available
authorKefu Chai <kchai@redhat.com>
Fri, 27 Nov 2020 16:31:00 +0000 (00:31 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 27 Nov 2020 16:31:44 +0000 (00:31 +0800)
and use "<experimental/filesystem>" as a fallback.

since GCC-9 has included <filesystem> already.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/admin_socket_output.cc
src/test/admin_socket_output.h
src/test/common/test_util.cc
src/test/immutable_object_cache/test_object_store.cc
src/tools/immutable_object_cache/ObjectCacheStore.cc

index 76e6e567726fd6a15531ca9a27c205cbb6efd85b..b178e3841cd3d93410cbc9cf313c88dd264cce85 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <iostream>
 #include <regex>                 // For regex, regex_search
-#include <experimental/filesystem> // For extension
 
 #include "common/admin_socket_client.h"     // For AdminSocketClient
 #include "common/ceph_json.h"               // For JSONParser, JSONObjIter
index e8e65d69ed4f27bcffb9463bd5eba174b49ef400..b09f05167c4f01ab6228269c8165c4c195bc493e 100644 (file)
 #include <map>
 #include <set>
 #include <vector>
-#include <experimental/filesystem>       // For path
-
+#if __has_include(<filesystem>)         // For extension
+#include <filesystem>
+namespace fs = std::filesystem;
+#else
+#include <experimental/filesystem>
 namespace fs = std::experimental::filesystem;
+#endif
 
 using socket_results = std::map<std::string, std::string>;
 using test_functions =
index cf589bafc843c5261bd509da0a332af72bed27ca..6249d387656d39a3238cdf7e3df60288d75eac05 100644 (file)
 #include "include/util.h"
 #include "gtest/gtest.h"
 
+#if __has_include(<filesystem>)
+#include <filesystem>
+namespace fs = std::filesystem;
+#else
 #include <experimental/filesystem>
+namespace fs = std::experimental::filesystem;
+#endif
 
 #if defined(__linux__)
 TEST(util, collect_sys_info)
 {
-  if (!std::experimental::filesystem::exists("/etc/os-release")) {
+  if (!fs::exists("/etc/os-release")) {
     GTEST_SKIP() << "skipping as '/etc/os-release' does not exist";
   }
 
index 736928fe0e7dca794df70a4de7425564d0e15202..6d2875a7d3ed3ddf690ec0161ff87079ce7a211b 100644 (file)
@@ -4,7 +4,13 @@
 #include <iostream>
 #include <unistd.h>
 
+#if __has_include(<filesystem>)
+#include <filesystem>
+namespace fs = std::filesystem;
+#else
 #include <experimental/filesystem>
+namespace fs = std::experimental::filesystem;
+#endif
 
 #include "gtest/gtest.h"
 #include "include/Context.h"
@@ -18,7 +24,6 @@
 
 #include "tools/immutable_object_cache/ObjectCacheStore.h"
 
-namespace efs = std::experimental::filesystem;
 using namespace ceph::immutable_obj_cache;
 
 std::string test_cache_path("/tmp/test_ceph_immutable_shared_cache");
@@ -85,7 +90,7 @@ TEST_F(TestObjectStore, test_1) {
 
   std::string cache_path(test_cache_path);
 
-  efs::remove_all(test_cache_path);
+  fs::remove_all(test_cache_path);
 
   init_object_cache_store(m_temp_pool_name, m_temp_volume_name, 1000, true);
 
index a0b2b27ce1629af4f2ce5852a106b8b870a2b4ba..cee1ca2b65ddea61affcdff0d38ed21c60b5377b 100644 (file)
@@ -3,7 +3,13 @@
 
 #include "ObjectCacheStore.h"
 #include "Utils.h"
+#if __has_include(<filesystem>)
+#include <filesystem>
+namespace fs = std::filesystem;
+#else
 #include <experimental/filesystem>
+namespace fs = std::experimental::filesystem;
+#endif
 
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_immutable_obj_cache
@@ -11,7 +17,6 @@
 #define dout_prefix *_dout << "ceph::cache::ObjectCacheStore: " << this << " " \
                            << __func__ << ": "
 
-namespace efs = std::experimental::filesystem;
 
 namespace ceph {
 namespace immutable_obj_cache {
@@ -61,15 +66,15 @@ int ObjectCacheStore::init(bool reset) {
   // TODO(dehao): fsck and reuse existing cache objects
   if (reset) {
     try {
-      if (efs::exists(m_cache_root_dir)) {
+      if (fs::exists(m_cache_root_dir)) {
         // remove all sub folders
-        for (auto& p : efs::directory_iterator(m_cache_root_dir)) {
-          efs::remove_all(p.path());
+        for (auto& p : fs::directory_iterator(m_cache_root_dir)) {
+          fs::remove_all(p.path());
         }
       } else {
-        efs::create_directories(m_cache_root_dir);
+        fs::create_directories(m_cache_root_dir);
       }
-    } catch (const efs::filesystem_error& e) {
+    } catch (const fs::filesystem_error& e) {
       lderr(m_cct) << "failed to initialize cache store directory: "
                    << e.what() << dendl;
       return -e.code().value();
@@ -287,12 +292,12 @@ std::string ObjectCacheStore::get_cache_file_path(std::string cache_file_name,
     ldout(m_cct, 20) << "creating cache dir: " << cache_file_dir <<dendl;
     std::error_code ec;
     std::string new_dir = m_cache_root_dir + cache_file_dir;
-    if (efs::exists(new_dir, ec)) {
+    if (fs::exists(new_dir, ec)) {
       ldout(m_cct, 20) << "cache dir exists: " << cache_file_dir <<dendl;
       return new_dir + cache_file_name;
     }
 
-    if (!efs::create_directories(new_dir, ec)) {
+    if (!fs::create_directories(new_dir, ec)) {
       ldout(m_cct, 5) << "fail to create cache dir: " << new_dir
                       << "error: " << ec.message() << dendl;
       return "";