From 3b739b6811642f2bd1f6009a0d3284352961db02 Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Tue, 26 Oct 2021 13:37:10 +0200
Subject: [PATCH] Replace boost::filesystem with std::filesystem

---
 include/caosdb/certificate_provider.h         |  4 +-
 include/caosdb/configuration.h                | 13 +++----
 include/caosdb/connection.h                   | 10 ++---
 include/caosdb/entity.h                       | 13 +++----
 .../caosdb/file_transmission/file_reader.h    | 18 ++++-----
 .../caosdb/file_transmission/file_writer.h    | 10 ++---
 include/caosdb/utility.h                      | 38 +++++++++----------
 src/caosdb/configuration.cpp                  |  4 +-
 .../download_request_handler.cpp              |  2 +-
 src/caosdb/file_transmission/file_reader.cpp  |  5 +--
 src/caosdb/file_transmission/file_writer.cpp  |  4 +-
 .../upload_request_handler.cpp                |  2 +-
 src/caosdb/transaction.cpp                    |  2 +-
 src/ccaosdb.cpp                               |  2 +-
 test/test_file_transmission.cpp               | 16 ++++----
 15 files changed, 67 insertions(+), 76 deletions(-)

diff --git a/include/caosdb/certificate_provider.h b/include/caosdb/certificate_provider.h
index e7d7a15..1fd4a80 100644
--- a/include/caosdb/certificate_provider.h
+++ b/include/caosdb/certificate_provider.h
@@ -22,9 +22,9 @@
 #ifndef CAOSDB_CERTIFICATE_PROVIDER_H
 #define CAOSDB_CERTIFICATE_PROVIDER_H
 
-#include "boost/filesystem/path.hpp" // for path
+#include <filesystem> // for path
 namespace caosdb::configuration {
-using boost::filesystem::path;
+using std::filesystem::path;
 
 class CertificateProvider {
 public:
diff --git a/include/caosdb/configuration.h b/include/caosdb/configuration.h
index 2c521e7..be51bab 100644
--- a/include/caosdb/configuration.h
+++ b/include/caosdb/configuration.h
@@ -21,11 +21,9 @@
 
 #ifndef CAOSDB_CONFIGURATION_H
 #define CAOSDB_CONFIGURATION_H
-#include "boost/filesystem/operations.hpp" // for exists
-#include "boost/filesystem/path.hpp"       // for path
-#include "boost/json/object.hpp"           // for object
-#include "boost/json/value.hpp"            // for value
-#include "boost/json/value_ref.hpp"        // IWYU pragma: keep
+#include "boost/json/object.hpp"    // for object
+#include "boost/json/value.hpp"     // for value
+#include "boost/json/value_ref.hpp" // IWYU pragma: keep
 // IWYU pragma: no_include "boost/json/fwd.hpp"
 #include "caosdb/authentication.h"       // for Authenticator, PlainPassw...
 #include "caosdb/certificate_provider.h" // for CertificateProvider, path
@@ -34,12 +32,11 @@
 #include "caosdb/utility.h"              // for load_json_file
 #include "grpcpp/security/credentials.h" // for ChannelCredentials
 #include <iosfwd>                        // for ostream
+#include <filesystem>                    // for exists
 #include <memory>                        // for unique_ptr, shared_ptr
 #include <string>                        // for string
 
 namespace caosdb::configuration {
-using boost::filesystem::exists;
-using boost::filesystem::path;
 using boost::json::array;
 using boost::json::object;
 using boost::json::value;
@@ -48,6 +45,8 @@ using caosdb::authentication::PlainPasswordAuthenticator;
 using caosdb::exceptions::ConfigurationError;
 using caosdb::utility::load_json_file;
 using grpc::ChannelCredentials;
+using std::filesystem::exists;
+using std::filesystem::path;
 
 const std::string logger_name = "caosdb::configuration";
 
diff --git a/include/caosdb/connection.h b/include/caosdb/connection.h
index d3ed094..f9aaa8b 100644
--- a/include/caosdb/connection.h
+++ b/include/caosdb/connection.h
@@ -27,10 +27,6 @@
  * @date 2021-05-18
  * @brief Configuration and setup of the connection.
  */
-#include <map>                                   // for map
-#include <memory>                                // for shared_ptr, unique_ptr
-#include <string>                                // for string, basic_string
-#include "boost/filesystem/path.hpp"             // for path
 #include "caosdb/authentication.h"               // for Authenticator
 #include "caosdb/configuration.h"                // for ConnectionConfigura...
 #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for EntityTransactionSe...
@@ -39,9 +35,12 @@
 #include "caosdb/transaction.h"                  // for Transaction
 #include "caosdb/transaction_status.h"           // for TransactionStatus
 #include "grpcpp/channel.h"                      // for Channel
+#include <filesystem>                            // for path
+#include <map>                                   // for map
+#include <memory>                                // for shared_ptr, unique_ptr
+#include <string>                                // for string, basic_string
 
 namespace caosdb::connection {
-using boost::filesystem::path;
 using caosdb::authentication::Authenticator;
 using caosdb::configuration::ConnectionConfiguration;
 using caosdb::entity::v1alpha1::EntityTransactionService;
@@ -50,6 +49,7 @@ using caosdb::info::VersionInfo;
 using caosdb::info::v1alpha1::GeneralInfoService;
 using caosdb::transaction::Transaction;
 using caosdb::transaction::TransactionStatus;
+using std::filesystem::path;
 
 /**
  * @brief A reusable connection to a CaosDBServer.
diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h
index 6de939c..3e24624 100644
--- a/include/caosdb/entity.h
+++ b/include/caosdb/entity.h
@@ -36,14 +36,13 @@
 #include "caosdb/protobuf_helper.h"                    // for get_arena
 #include "caosdb/status_code.h"                        // for StatusCode
 #include "caosdb/value.h"                              // for Value
-#include <boost/filesystem/operations.hpp>             // for exists, is_di...
-#include <boost/filesystem/path.hpp>                   // for path
 #include <boost/log/core/record.hpp>                   // for record
 #include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring...
 #include <boost/log/sources/record_ostream.hpp>        // for basic_record_...
 #include <boost/preprocessor/seq/limits/enum_256.hpp>  // for BOOST_PP_SEQ_...
 #include <boost/preprocessor/seq/limits/size_256.hpp>  // for BOOST_PP_SEQ_...
 #include <cstdint>                                     // for int64_t
+#include <filesystem>                                  // for path
 #include <google/protobuf/message.h>                   // for RepeatedPtrField
 #include <iosfwd>                                      // for streamsize
 #include <iterator>                                    // for iterator, output_iterato...
@@ -55,9 +54,9 @@
 #include <utility>                                     // for move
 
 namespace caosdb::entity {
-using boost::filesystem::exists;
-using boost::filesystem::is_directory;
 using caosdb::entity::v1alpha1::IdResponse;
+using std::filesystem::exists;
+using std::filesystem::is_directory;
 using ProtoParent = caosdb::entity::v1alpha1::Parent;
 using ProtoProperty = caosdb::entity::v1alpha1::Property;
 using ProtoEntity = caosdb::entity::v1alpha1::Entity;
@@ -113,7 +112,7 @@ const std::map<Role, std::string> role_names = {{Role::UNSPECIFIED, "UNSPECIFIED
 struct FileDescriptor {
   FileTransmissionId *file_transmission_id;
   ProtoFileDescriptor *wrapped;
-  boost::filesystem::path local_path;
+  std::filesystem::path local_path;
 };
 
 /**
@@ -756,11 +755,11 @@ public:
 
   inline auto GetFileDescriptor() -> FileDescriptor & { return this->file_descriptor; }
 
-  inline auto GetLocalPath() const noexcept -> const boost::filesystem::path & {
+  inline auto GetLocalPath() const noexcept -> const std::filesystem::path & {
     return this->file_descriptor.local_path;
   }
 
-  inline auto SetLocalPath(const boost::filesystem::path &local_path) noexcept -> StatusCode {
+  inline auto SetLocalPath(const std::filesystem::path &local_path) noexcept -> StatusCode {
     if (GetRole() != Role::FILE) {
       CAOSDB_LOG_WARN(logger_name) << "Entity::SetLocalPath failed. This is not a file entity.";
       return StatusCode::NOT_A_FILE_ENTITY;
diff --git a/include/caosdb/file_transmission/file_reader.h b/include/caosdb/file_transmission/file_reader.h
index 67c1247..2c52f17 100644
--- a/include/caosdb/file_transmission/file_reader.h
+++ b/include/caosdb/file_transmission/file_reader.h
@@ -49,20 +49,18 @@
 #ifndef CAOSDB_FILE_TRANSMISSION_FILE_READER_H
 #define CAOSDB_FILE_TRANSMISSION_FILE_READER_H
 
-#include <boost/filesystem/fstream.hpp>    // for ifstream
-#include <boost/filesystem/operations.hpp> // for exists
-#include <boost/filesystem/path.hpp>       // for path
-#include <fstream>                         // for ifstream, size_t
-#include <string>                          // for string
+#include <filesystem> // for ifstream
+#include <fstream>    // for ifstream, size_t
+#include <string>     // for string
 
 namespace caosdb::transaction {
-using boost::filesystem::exists;
-using boost::filesystem::ifstream;
-using boost::filesystem::path;
+using std::ifstream;
+using std::filesystem::exists;
+using std::filesystem::path;
 
 class FileReader final {
 public:
-  FileReader(boost::filesystem::path filename);
+  FileReader(std::filesystem::path filename);
 
   ~FileReader() = default;
 
@@ -80,7 +78,7 @@ private:
   void openFile();
 
   std::ifstream stream_;
-  boost::filesystem::path filename_;
+  std::filesystem::path filename_;
   unsigned long long size_;
 };
 
diff --git a/include/caosdb/file_transmission/file_writer.h b/include/caosdb/file_transmission/file_writer.h
index 801d74b..165178b 100644
--- a/include/caosdb/file_transmission/file_writer.h
+++ b/include/caosdb/file_transmission/file_writer.h
@@ -49,15 +49,15 @@
 #ifndef CAOSDB_FILE_TRANSMISSION_FILE_WRITER_H
 #define CAOSDB_FILE_TRANSMISSION_FILE_WRITER_H
 
-#include <boost/filesystem/path.hpp> // for path
-#include <fstream>                   // for ofstream
-#include <string>                    // for string
+#include <filesystem> // for path
+#include <fstream>    // for ofstream
+#include <string>     // for string
 
 namespace caosdb::transaction {
 
 class FileWriter final {
 public:
-  FileWriter(boost::filesystem::path filename);
+  FileWriter(std::filesystem::path filename);
 
   ~FileWriter() = default;
 
@@ -73,7 +73,7 @@ private:
   void openFile();
 
   std::ofstream stream_;
-  boost::filesystem::path filename_;
+  std::filesystem::path filename_;
 };
 
 } // namespace caosdb::transaction
diff --git a/include/caosdb/utility.h b/include/caosdb/utility.h
index 5af1b49..2822e0c 100644
--- a/include/caosdb/utility.h
+++ b/include/caosdb/utility.h
@@ -25,28 +25,26 @@
 #include "caosdb/entity.h"                    // for Importance, Role
 #include <boost/beast/core/detail/base64.hpp> // for encoded_size
 #include <boost/beast/core/detail/base64.ipp> // for encode
-#include <boost/filesystem/operations.hpp>    // for exists
-#include <boost/filesystem/path.hpp>          // for path
-#include <boost/filesystem/fstream.hpp>       // for basic_ifstream, ifstream
-#include <boost/filesystem/string_file.hpp>   // for load_string_file
-#include <boost/json/stream_parser.hpp>       // for stream_parser
-#include <boost/json/value.hpp>               // for value
-#include <boost/lexical_cast.hpp>             // for lexical_cast
-#include <cassert>                            // for assert
-#include <cstdlib>                            // for getenv
-#include <fstream>                            // for basic_istream<>::__ist...
-#include <memory>                             // for allocator, unique_ptr
-#include <stdexcept>                          // for logic_error
-#include <string>                             // for string, operator+, cha...
-#include <type_traits>                        // for underlying_type_t
-#include <typeinfo>                           // for type_info
+#include <boost/filesystem.hpp>
+#include <boost/json/stream_parser.hpp> // for stream_parser
+#include <boost/json/value.hpp>         // for value
+#include <boost/lexical_cast.hpp>       // for lexical_cast
+#include <cassert>                      // for assert
+#include <cstdlib>                      // for getenv
+#include <filesystem>                   // for path
+#include <fstream>                      // for basic_istream<>::__ist...
+#include <memory>                       // for allocator, unique_ptr
+#include <stdexcept>                    // for logic_error
+#include <string>                       // for string, operator+, cha...
+#include <type_traits>                  // for underlying_type_t
+#include <typeinfo>                     // for type_info
 
 namespace caosdb::utility {
-using boost::filesystem::exists;
-using boost::filesystem::ifstream;
-using boost::filesystem::path;
 using boost::json::stream_parser;
 using boost::json::value;
+using std::ifstream;
+using std::filesystem::exists;
+using std::filesystem::path;
 
 /**
  * @brief Get the name of the enum value.  May be useful for higher-order CaosDB clients.
@@ -86,9 +84,9 @@ auto getEnumValueFromName<caosdb::entity::Role>(const std::string &name) -> caos
 /**
  * @brief Read a text file into a string and return the file's content.
  */
-inline auto load_string_file(const path &path) -> std::string {
+inline auto load_string_file(const std::string &file_path) -> std::string {
   std::string result;
-  boost::filesystem::load_string_file(path, result);
+  boost::filesystem::load_string_file(file_path, result);
   return result;
 }
 
diff --git a/src/caosdb/configuration.cpp b/src/caosdb/configuration.cpp
index edce302..b08046d 100644
--- a/src/caosdb/configuration.cpp
+++ b/src/caosdb/configuration.cpp
@@ -47,8 +47,6 @@
 #include <string>                        // for string, operator+
 
 namespace caosdb::configuration {
-using boost::filesystem::exists;
-using boost::filesystem::path;
 using boost::json::object;
 using boost::json::value;
 using caosdb::authentication::Authenticator;
@@ -66,6 +64,8 @@ using caosdb::utility::load_string_file;
 using grpc::InsecureChannelCredentials;
 using grpc::SslCredentials;
 using grpc::SslCredentialsOptions;
+using std::filesystem::exists;
+using std::filesystem::path;
 
 PemFileCertificateProvider::PemFileCertificateProvider(const path &path) {
   this->certificate_provider = load_string_file(path);
diff --git a/src/caosdb/file_transmission/download_request_handler.cpp b/src/caosdb/file_transmission/download_request_handler.cpp
index cbe79e9..5887e53 100644
--- a/src/caosdb/file_transmission/download_request_handler.cpp
+++ b/src/caosdb/file_transmission/download_request_handler.cpp
@@ -51,7 +51,6 @@
 #include "caosdb/protobuf_helper.h"                    // for get_arena
 #include "caosdb/status_code.h"                        // for GENERIC_RPC_E...
 #include "caosdb/transaction_status.h"                 // for TransactionStatus
-#include <boost/filesystem/path.hpp>                   // for operator<<, path
 #include <boost/log/core/record.hpp>                   // for record
 #include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring...
 #include <boost/log/sources/record_ostream.hpp>        // for basic_record_...
@@ -59,6 +58,7 @@
 #include <boost/preprocessor/seq/limits/size_256.hpp>  // for BOOST_PP_SEQ_...
 #include <exception>                                   // IWYU pragma: keep
 // IWYU pragma: no_include <bits/exception.h>
+#include <filesystem>                             // for operator<<, path
 #include <google/protobuf/arena.h>                // for Arena
 #include <grpcpp/impl/codegen/async_stream.h>     // for ClientAsyncRe...
 #include <grpcpp/impl/codegen/client_context.h>   // for ClientContext
diff --git a/src/caosdb/file_transmission/file_reader.cpp b/src/caosdb/file_transmission/file_reader.cpp
index f118eca..3d08f5d 100644
--- a/src/caosdb/file_transmission/file_reader.cpp
+++ b/src/caosdb/file_transmission/file_reader.cpp
@@ -48,13 +48,12 @@
  */
 #include "caosdb/file_transmission/file_reader.h"
 #include "caosdb/file_transmission/file_error.h" // for FileIOError
-#include <boost/filesystem/path.hpp>             // for path
+#include <filesystem>                            // for path
 #include <utility>                               // for move
 
 namespace caosdb::transaction {
 
-FileReader::FileReader(boost::filesystem::path filename)
-  : filename_(std::move(filename)), size_(0) {
+FileReader::FileReader(std::filesystem::path filename) : filename_(std::move(filename)), size_(0) {
   this->openFile();
 }
 
diff --git a/src/caosdb/file_transmission/file_writer.cpp b/src/caosdb/file_transmission/file_writer.cpp
index 5cf7d3a..3f49ea4 100644
--- a/src/caosdb/file_transmission/file_writer.cpp
+++ b/src/caosdb/file_transmission/file_writer.cpp
@@ -48,12 +48,12 @@
  */
 #include "caosdb/file_transmission/file_writer.h"
 #include "caosdb/file_transmission/file_error.h" // for FileIOError
-#include <boost/filesystem/path.hpp>             // for path
+#include <filesystem>                            // for path
 #include <utility>                               // for move
 
 namespace caosdb::transaction {
 
-FileWriter::FileWriter(boost::filesystem::path filename) : filename_(std::move(filename)) {
+FileWriter::FileWriter(std::filesystem::path filename) : filename_(std::move(filename)) {
   this->openFile();
 }
 
diff --git a/src/caosdb/file_transmission/upload_request_handler.cpp b/src/caosdb/file_transmission/upload_request_handler.cpp
index bc74391..f43448e 100644
--- a/src/caosdb/file_transmission/upload_request_handler.cpp
+++ b/src/caosdb/file_transmission/upload_request_handler.cpp
@@ -52,7 +52,6 @@
 #include "caosdb/status_code.h"                        // for GENERIC_RPC_E...
 #include "caosdb/transaction_status.h"                 // for TransactionStatus
 #include <algorithm>                                   // for min
-#include <boost/filesystem/path.hpp>                   // for operator<<, path
 #include <boost/log/core/record.hpp>                   // for record
 #include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring...
 #include <boost/log/sources/record_ostream.hpp>        // for basic_record_...
@@ -61,6 +60,7 @@
 #include <cstdint>                                     // for uint64_t
 #include <exception>                                   // IWYU pragma: keep
 // IWYU pragma: no_include <bits/exception.h>
+#include <filesystem>                             // for operator<<, path
 #include <google/protobuf/arena.h>                // for Arena
 #include <grpcpp/impl/codegen/async_stream.h>     // for ClientAsyncWr...
 #include <grpcpp/impl/codegen/call_op_set.h>      // for WriteOptions
diff --git a/src/caosdb/transaction.cpp b/src/caosdb/transaction.cpp
index 637112d..416d36f 100644
--- a/src/caosdb/transaction.cpp
+++ b/src/caosdb/transaction.cpp
@@ -28,7 +28,6 @@
 #include "caosdb/status_code.h"                                    // for StatusCode
 #include "caosdb/transaction_handler.h"                            // for EntityTransactionHandler
 #include <algorithm>                                               // for max
-#include <boost/filesystem/path.hpp>                               // for operator<<, path
 #include <boost/log/core/record.hpp>                               // for record
 #include <boost/log/detail/attachable_sstream_buf.hpp>             // for basic_ostring...
 #include <boost/log/sources/record_ostream.hpp>                    // for basic_record_...
@@ -36,6 +35,7 @@
 #include <boost/preprocessor/seq/limits/size_256.hpp>              // for BOOST_PP_SEQ_...
 // IWYU pragma: no_include <bits/exception.h>
 #include <exception>                              // IWYU pragma: keep
+#include <filesystem>                             // for operator<<, path
 #include <google/protobuf/arena.h>                // for Arena
 #include <grpc/impl/codegen/gpr_types.h>          // for gpr_timespec
 #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp
index 77759fc..d33d74e 100644
--- a/src/ccaosdb.cpp
+++ b/src/ccaosdb.cpp
@@ -1115,7 +1115,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
                   })
 CAOSDB_ENTITY_SET(name, name, wrapped_entity->SetName(std::string(name));)
 CAOSDB_ENTITY_SET(local_path, local_path,
-                  return wrapped_entity->SetLocalPath(boost::filesystem::path(local_path));)
+                  return wrapped_entity->SetLocalPath(std::filesystem::path(local_path));)
 CAOSDB_ENTITY_SET(file_path, file_path, wrapped_entity->SetFilePath(std::string(file_path));)
 CAOSDB_ENTITY_SET(description, description,
                   wrapped_entity->SetDescription(std::string(description));)
diff --git a/test/test_file_transmission.cpp b/test/test_file_transmission.cpp
index 7c5eb74..7903c91 100644
--- a/test/test_file_transmission.cpp
+++ b/test/test_file_transmission.cpp
@@ -19,15 +19,13 @@
  */
 #include "caosdb/file_transmission/file_writer.h"
 #include "caosdb/file_transmission/file_reader.h"
-#include <boost/filesystem/operations.hpp>  // for exists, file_size, remove
-#include <boost/filesystem/path.hpp>        // for path
-#include <boost/filesystem/path_traits.hpp> // for filesystem
-#include <gtest/gtest-message.h>            // for Message
-#include <gtest/gtest-test-part.h>          // for TestPartResult, SuiteApiResolver
-#include <gtest/gtest_pred_impl.h>          // for Test, EXPECT_EQ, AssertionResult
-#include <string>                           // for string
-
-namespace fs = boost::filesystem;
+#include <filesystem>              // for path
+#include <gtest/gtest-message.h>   // for Message
+#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver
+#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult
+#include <string>                  // for string
+
+namespace fs = std::filesystem;
 
 namespace caosdb::transaction {
 
-- 
GitLab