From e429a96601fee8a39c5a858f0814597b192de3c1 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 10 Aug 2022 12:14:52 +0200 Subject: [PATCH] Use boost::filesystem if std::filesystem is not available --- src/algorithms/libs/rtklib/CMakeLists.txt | 10 ++++++++++ src/algorithms/libs/rtklib/rtklib_rtkcmn.cc | 6 +++--- src/algorithms/libs/rtklib/rtklib_rtkcmn.h | 21 +++++++++++++++++++-- src/algorithms/libs/rtklib/rtklib_stream.cc | 16 ++++++++-------- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/algorithms/libs/rtklib/CMakeLists.txt b/src/algorithms/libs/rtklib/CMakeLists.txt index ec7958c02..8bab07358 100644 --- a/src/algorithms/libs/rtklib/CMakeLists.txt +++ b/src/algorithms/libs/rtklib/CMakeLists.txt @@ -74,6 +74,16 @@ target_link_libraries(algorithms_libs_rtklib BLAS::BLAS ) +if(FILESYSTEM_FOUND) + target_compile_definitions(algorithms_libs_rtklib PUBLIC -DHAS_STD_FILESYSTEM=1) + if(find_experimental) + target_compile_definitions(algorithms_libs_rtklib PUBLIC -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() + target_link_libraries(algorithms_libs_rtklib PUBLIC std::filesystem) +else() + target_link_libraries(algorithms_libs_rtklib PUBLIC Boost::filesystem Boost::system) +endif() + set_property(TARGET algorithms_libs_rtklib APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $ diff --git a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc index 792bb46dc..9cb21816a 100644 --- a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc +++ b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc @@ -4118,11 +4118,11 @@ int execcmd(const char *cmd) * return : none * notes : not recursive. only one level *-----------------------------------------------------------------------------*/ -void createdir(std::filesystem::path const &path) +void createdir(fs::path const &path) { - std::error_code ec; + errorlib::error_code ec; - auto created = std::filesystem::create_directory(path, ec); + auto created = fs::create_directory(path, ec); if (not created) { trace(1, "Error creating folder: %s", path.c_str()); diff --git a/src/algorithms/libs/rtklib/rtklib_rtkcmn.h b/src/algorithms/libs/rtklib/rtklib_rtkcmn.h index 3f6b0f1c0..d606d4d4e 100644 --- a/src/algorithms/libs/rtklib/rtklib_rtkcmn.h +++ b/src/algorithms/libs/rtklib/rtklib_rtkcmn.h @@ -60,9 +60,26 @@ #include "rtklib.h" #include -#include #include +#if HAS_STD_FILESYSTEM +#include +namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else +#include +namespace fs = std::filesystem; +#endif +#else +#include // for create_directories, exists +#include // for path, operator<< +#include // for filesystem +#include // for error_code +namespace fs = boost::filesystem; +namespace errorlib = boost::system; +#endif /* coordinate rotation matrix ------------------------------------------------*/ #define Rx(t, X) \ @@ -230,7 +247,7 @@ void traceobs(int level, const obsd_t *obs, int n); // void traceb (int level, const unsigned char *p, int n); int execcmd(const char *cmd); -void createdir(std::filesystem::path const &path); +void createdir(fs::path const &path); int reppath(std::string const &path, std::string &rpath, gtime_t time, const char *rov, const char *base); double satwavelen(int sat, int frq, const nav_t *nav); diff --git a/src/algorithms/libs/rtklib/rtklib_stream.cc b/src/algorithms/libs/rtklib/rtklib_stream.cc index 7752494cb..6c7a10b02 100644 --- a/src/algorithms/libs/rtklib/rtklib_stream.cc +++ b/src/algorithms/libs/rtklib/rtklib_stream.cc @@ -1946,12 +1946,12 @@ void *ftpthread(void *arg) std::string remote; reppath(ftp->file, remote, time, "", ""); - auto remotePath = std::filesystem::path(remote); + auto remotePath = fs::path(remote); - auto local = std::filesystem::path(localdir); + auto local = fs::path(localdir); local /= remotePath.filename(); - auto errfile = std::filesystem::path(local); + auto errfile = fs::path(local); errfile.replace_extension("err"); /* if local file exist, skip download */ @@ -1964,7 +1964,7 @@ void *ftpthread(void *arg) break; } } - if (std::filesystem::exists(tmpfile)) + if (fs::exists(tmpfile)) { std::strncpy(ftp->local, tmpfile.c_str(), 1024); ftp->local[1023] = '\0'; @@ -2005,11 +2005,11 @@ void *ftpthread(void *arg) R"("http://)"s + std::string(ftp->addr) + "/"s + remotePath.native() + R"(" 2> ")"s + errfile.native() + "\"\n"; } /* execute download command */ - std::error_code ec; // prevent exceptions + errorlib::error_code ec; // prevent exceptions auto ret = execcmd(cmd_str.c_str()); if ((ret != 0)) { - if (std::filesystem::remove(local, ec) == false) + if (fs::remove(local, ec) == false) { trace(1, "Error removing file %s", local.c_str()); } @@ -2018,7 +2018,7 @@ void *ftpthread(void *arg) ftp->state = 3; return nullptr; } - if (std::filesystem::remove(errfile, ec) == false) + if (fs::remove(errfile, ec) == false) { trace(1, "Error removing file %s", errfile.c_str()); } @@ -2032,7 +2032,7 @@ void *ftpthread(void *arg) ret = rtk_uncompress(local.c_str(), tmpfile_arg); if (ret != 0) // success { - if (std::filesystem::remove(local, ec) == false) + if (fs::remove(local, ec) == false) { trace(1, "Error removing file %s", local.c_str()); }