This is an automated email from the ASF dual-hosted git repository.

rmiddleton pushed a commit to branch LOGCXX-518
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/LOGCXX-518 by this push:
     new 5b2300a2 check for std::experimental::filesystem and switch things 
over to use standard filesystem
5b2300a2 is described below

commit 5b2300a2f7d7a51eddea2ec7ba11b10237692b68
Author: Robert Middleton <[email protected]>
AuthorDate: Sat Oct 22 09:55:35 2022 -0400

    check for std::experimental::filesystem and switch things over to use 
standard filesystem
---
 src/cmake/boost-fallback/boost-fallback.cmake            | 3 +++
 src/cmake/boost-fallback/boost-std-configuration.h.cmake | 8 ++++++++
 src/cmake/boost-fallback/test-stdexpfilesystem.cpp       | 5 +++++
 src/main/cpp/multiprocessrollingfileappender.cpp         | 5 +++--
 src/main/include/CMakeLists.txt                          | 2 ++
 5 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/cmake/boost-fallback/boost-fallback.cmake 
b/src/cmake/boost-fallback/boost-fallback.cmake
index 3a71c929..8de5f314 100644
--- a/src/cmake/boost-fallback/boost-fallback.cmake
+++ b/src/cmake/boost-fallback/boost-fallback.cmake
@@ -45,6 +45,7 @@
 #
 # Filesystem variables set:
 # STD_FILESYSTEM_FOUND - if std::filesystem is found
+# STD_EXPERIMENTAL_FILESYSTEM_FOUND - if std::experimental::filesystem is found
 # Boost_FILESYSTEM_FOUND - if boost::filesystem is found
 
 include(FindThreads)
@@ -61,6 +62,8 @@ try_compile(STD_ATOMIC_FOUND 
"${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
     "${CMAKE_CURRENT_LIST_DIR}/test-stdatomic.cpp")
 try_compile(STD_FILESYSTEM_FOUND 
"${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
     "${CMAKE_CURRENT_LIST_DIR}/test-stdfilesystem.cpp")
+try_compile(STD_EXPERIMENTAL_FILESYSTEM_FOUND 
"${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
+    "${CMAKE_CURRENT_LIST_DIR}/test-stdexpfilesystem.cpp")
 
 # We need to have all three boost components in order to run our tests
 # Boost thread requires chrono and atomic to work
diff --git a/src/cmake/boost-fallback/boost-std-configuration.h.cmake 
b/src/cmake/boost-fallback/boost-std-configuration.h.cmake
index 1e5dcf5a..9ccf8fd9 100644
--- a/src/cmake/boost-fallback/boost-std-configuration.h.cmake
+++ b/src/cmake/boost-fallback/boost-std-configuration.h.cmake
@@ -5,6 +5,7 @@
 #cmakedefine01 Boost_SHARED_MUTEX_FOUND
 #cmakedefine01 STD_FILESYSTEM_FOUND
 #cmakedefine01 Boost_FILESYSTEM_FOUND
+#cmakedefine01 STD_EXPERIMENTAL_FILESYSTEM_FOUND
 
 #if STD_SHARED_MUTEX_FOUND
 #include <shared_mutex>
@@ -29,6 +30,13 @@ namespace filesystem {
     typedef std::filesystem::path path;
 }
 }
+#elif STD_EXPERIMENTAL_FILESYSTEM_FOUND
+#include <experimental/filesystem>
+namespace ${NAMESPACE_ALIAS} {
+namespace filesystem {
+    typedef std::experimental::filesystem::path path;
+}
+}
 #elif Boost_FILESYSTEM_FOUND
 #include <boost/filesystem.hpp>
 namespace ${NAMESPACE_ALIAS} {
diff --git a/src/cmake/boost-fallback/test-stdexpfilesystem.cpp 
b/src/cmake/boost-fallback/test-stdexpfilesystem.cpp
new file mode 100644
index 00000000..6062572d
--- /dev/null
+++ b/src/cmake/boost-fallback/test-stdexpfilesystem.cpp
@@ -0,0 +1,5 @@
+#include <experimental/filesystem>
+
+int main(int argc, char** argv){
+       std::experimental::filesystem::path p;
+}
diff --git a/src/main/cpp/multiprocessrollingfileappender.cpp 
b/src/main/cpp/multiprocessrollingfileappender.cpp
index 6afe6a1f..e08aa4c8 100644
--- a/src/main/cpp/multiprocessrollingfileappender.cpp
+++ b/src/main/cpp/multiprocessrollingfileappender.cpp
@@ -21,7 +21,6 @@
 
 
 #include <apr_portable.h>
-#include <libgen.h>
 #include <apr_file_io.h>
 #include <apr_atomic.h>
 #include <apr_mmap.h>
@@ -41,6 +40,7 @@
 #include <log4cxx/helpers/transcoder.h>
 #include <log4cxx/private/fileappender_priv.h>
 #include <log4cxx/rolling/timebasedrollingpolicy.h>
+#include <log4cxx/boost-std-configuration.h>
 #include <mutex>
 
 using namespace log4cxx;
@@ -250,7 +250,8 @@ bool 
MultiprocessRollingFileAppender::rolloverInternal(Pool& p)
                                snprintf(szUid, MAX_FILE_LEN, "%u", uid);
                        }
 
-                       const std::string lockname = 
std::string(::dirname(szDirName)) + "/." + ::basename(szBaseName) + szUid + 
".lock";
+                       log4cxx::filesystem::path path = szDirName;
+                       const std::string lockname = path.parent_path() / 
(path.filename().string() + szUid + ".lock");
                        apr_file_t* lock_file;
                        stat = apr_file_open(&lock_file, lockname.c_str(), 
APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT, p.getAPRPool());
 
diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt
index 499ef852..dc168818 100644
--- a/src/main/include/CMakeLists.txt
+++ b/src/main/include/CMakeLists.txt
@@ -208,6 +208,8 @@ endif()
 
 if( ${STD_FILESYSTEM_FOUND} AND NOT ${PREFER_BOOST} )
        set( FILESYSTEM_IMPL "std::filesystem" )
+elseif( ${STD_EXPERIMENTAL_FILESYSTEM_FOUND} AND NOT ${PREFER_BOOST} )
+       set( FILESYSTEM_IMPL "std::experimental::filesystem" )
 elseif( ${Boost_FILESYSTEM_FOUND} )
        set( FILESYSTEM_IMPL "boost::filesystem" )
 else()

Reply via email to