1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-14 09:16:51 +00:00

Use boost::filesystem if std::filesystem is not available

This commit is contained in:
Carles Fernandez 2022-08-10 12:14:52 +02:00
parent 6e2c3b1cc4
commit e429a96601
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
4 changed files with 40 additions and 13 deletions

View File

@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>

View File

@ -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());

View File

@ -60,9 +60,26 @@
#include "rtklib.h"
#include <cstddef>
#include <filesystem>
#include <string>
#if HAS_STD_FILESYSTEM
#include <system_error>
namespace errorlib = std;
#if HAS_STD_FILESYSTEM_EXPERIMENTAL
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#include <filesystem>
namespace fs = std::filesystem;
#endif
#else
#include <boost/filesystem/operations.hpp> // for create_directories, exists
#include <boost/filesystem/path.hpp> // for path, operator<<
#include <boost/filesystem/path_traits.hpp> // for filesystem
#include <boost/system/error_code.hpp> // 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);

View File

@ -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());
}