Replace boost::filesystem with std (#6432)

This commit is contained in:
Dennis Luxen
2024-06-20 21:44:28 +02:00
committed by GitHub
parent c3f2a6cdb9
commit f1eabc3ecc
64 changed files with 417 additions and 311 deletions
+13 -14
View File
@@ -10,14 +10,13 @@
#include "util/log.hpp"
#include "util/version.hpp"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/seek.hpp>
#include <boost/iostreams/stream.hpp>
#include <cerrno>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <tuple>
#include <type_traits>
@@ -35,11 +34,11 @@ class FileReader
};
FileReader(const std::string &filename, const FingerprintFlag flag)
: FileReader(boost::filesystem::path(filename), flag)
: FileReader(std::filesystem::path(filename), flag)
{
}
FileReader(const boost::filesystem::path &filepath_, const FingerprintFlag flag)
FileReader(const std::filesystem::path &filepath_, const FingerprintFlag flag)
: filepath(filepath_), fingerprint(flag)
{
input_stream.open(filepath, std::ios::binary);
@@ -58,14 +57,14 @@ class FileReader
std::size_t GetSize()
{
const boost::filesystem::path path(filepath);
const std::filesystem::path path(filepath);
try
{
return std::size_t(boost::filesystem::file_size(path)) -
return std::size_t(std::filesystem::file_size(path)) -
((fingerprint == FingerprintFlag::VerifyFingerprint) ? sizeof(util::FingerPrint)
: 0);
}
catch (const boost::filesystem::filesystem_error &ex)
catch (const std::filesystem::filesystem_error &ex)
{
std::cout << ex.what() << std::endl;
throw;
@@ -196,8 +195,8 @@ class FileReader
}
private:
const boost::filesystem::path filepath;
boost::filesystem::ifstream input_stream;
const std::filesystem::path filepath;
std::ifstream input_stream;
FingerprintFlag fingerprint;
};
@@ -211,11 +210,11 @@ class FileWriter
};
FileWriter(const std::string &filename, const FingerprintFlag flag)
: FileWriter(boost::filesystem::path(filename), flag)
: FileWriter(std::filesystem::path(filename), flag)
{
}
FileWriter(const boost::filesystem::path &filepath_, const FingerprintFlag flag)
FileWriter(const std::filesystem::path &filepath_, const FingerprintFlag flag)
: filepath(filepath_), fingerprint(flag)
{
output_stream.open(filepath, std::ios::binary);
@@ -284,8 +283,8 @@ class FileWriter
}
private:
const boost::filesystem::path filepath;
boost::filesystem::ofstream output_stream;
const std::filesystem::path filepath;
std::ofstream output_stream;
FingerprintFlag fingerprint;
};
+13 -13
View File
@@ -3,19 +3,19 @@
#include "util/exception.hpp"
#include <array>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <array>
#include <filesystem>
#include <string>
namespace osrm::storage
{
struct IOConfig
{
IOConfig(std::vector<boost::filesystem::path> required_input_files_,
std::vector<boost::filesystem::path> optional_input_files_,
std::vector<boost::filesystem::path> output_files_)
IOConfig(std::vector<std::filesystem::path> required_input_files_,
std::vector<std::filesystem::path> optional_input_files_,
std::vector<std::filesystem::path> output_files_)
: required_input_files(std::move(required_input_files_)),
optional_input_files(std::move(optional_input_files_)),
output_files(std::move(output_files_))
@@ -24,7 +24,7 @@ struct IOConfig
bool IsValid() const;
std::vector<std::string> GetMissingFiles() const;
boost::filesystem::path GetPath(const std::string &fileName) const
std::filesystem::path GetPath(const std::string &fileName) const
{
if (!IsConfigured(fileName, required_input_files) &&
!IsConfigured(fileName, optional_input_files) && !IsConfigured(fileName, output_files))
@@ -40,11 +40,11 @@ struct IOConfig
return IsConfigured(fileName, required_input_files);
}
boost::filesystem::path base_path;
std::filesystem::path base_path;
protected:
// Infer the base path from the path of the .osrm file
void UseDefaultOutputNames(const boost::filesystem::path &base)
void UseDefaultOutputNames(const std::filesystem::path &base)
{
// potentially strip off the .osrm (or other) extensions for
// determining the base path=
@@ -67,7 +67,7 @@ struct IOConfig
private:
static bool IsConfigured(const std::string &fileName,
const std::vector<boost::filesystem::path> &paths)
const std::vector<std::filesystem::path> &paths)
{
for (auto &path : paths)
{
@@ -80,9 +80,9 @@ struct IOConfig
return false;
}
std::vector<boost::filesystem::path> required_input_files;
std::vector<boost::filesystem::path> optional_input_files;
std::vector<boost::filesystem::path> output_files;
std::vector<std::filesystem::path> required_input_files;
std::vector<std::filesystem::path> optional_input_files;
std::vector<std::filesystem::path> output_files;
};
} // namespace osrm::storage
+9 -9
View File
@@ -5,8 +5,6 @@
#include "util/exception_utils.hpp"
#include "util/log.hpp"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/interprocess/mapped_region.hpp>
#ifndef _WIN32
#include <boost/interprocess/xsi_shared_memory.hpp>
@@ -23,6 +21,8 @@
#include <algorithm>
#include <exception>
#include <filesystem>
#include <fstream>
#include <thread>
#include "storage/shared_memory_ownership.hpp"
@@ -32,10 +32,10 @@ namespace osrm::storage
struct OSRMLockFile
{
template <typename IdentifierT> boost::filesystem::path operator()(const IdentifierT &id)
template <typename IdentifierT> std::filesystem::path operator()(const IdentifierT &id)
{
boost::filesystem::path temp_dir = boost::filesystem::temp_directory_path();
boost::filesystem::path lock_file = temp_dir / ("osrm-" + std::to_string(id) + ".lock");
std::filesystem::path temp_dir = std::filesystem::temp_directory_path();
std::filesystem::path lock_file = temp_dir / ("osrm-" + std::to_string(id) + ".lock");
return lock_file;
}
};
@@ -51,7 +51,7 @@ class SharedMemory
SharedMemory &operator=(const SharedMemory &) = delete;
template <typename IdentifierT>
SharedMemory(const boost::filesystem::path &lock_file,
SharedMemory(const std::filesystem::path &lock_file,
const IdentifierT id,
const uint64_t size = 0)
: key(lock_file.string().c_str(), id)
@@ -202,7 +202,7 @@ class SharedMemory
void *Ptr() const { return region.get_address(); }
std::size_t Size() const { return region.get_size(); }
SharedMemory(const boost::filesystem::path &lock_file, const int id, const uint64_t size = 0)
SharedMemory(const std::filesystem::path &lock_file, const int id, const uint64_t size = 0)
{
sprintf(key, "%s.%d", "osrm.lock", id);
if (0 == size)
@@ -290,7 +290,7 @@ std::unique_ptr<SharedMemory> makeSharedMemory(const IdentifierT &id, const uint
try
{
LockFileT lock_file;
if (!boost::filesystem::exists(lock_file(id)))
if (!std::filesystem::exists(lock_file(id)))
{
if (0 == size)
{
@@ -298,7 +298,7 @@ std::unique_ptr<SharedMemory> makeSharedMemory(const IdentifierT &id, const uint
}
else
{
boost::filesystem::ofstream ofs(lock_file(id));
std::ofstream ofs(lock_file(id));
}
}
return std::make_unique<SharedMemory>(lock_file(id), id, size);
+5 -6
View File
@@ -32,15 +32,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "storage/shared_datatype.hpp"
#include "storage/storage_config.hpp"
#include <boost/filesystem/path.hpp>
#include <filesystem>
#include <string>
#include <vector>
namespace osrm::storage
{
void populateLayoutFromFile(const boost::filesystem::path &path, storage::BaseDataLayout &layout);
void populateLayoutFromFile(const std::filesystem::path &path, storage::BaseDataLayout &layout);
class Storage
{
@@ -51,10 +50,10 @@ class Storage
void PopulateStaticData(const SharedDataIndex &index);
void PopulateUpdatableData(const SharedDataIndex &index);
void PopulateLayout(storage::BaseDataLayout &layout,
const std::vector<std::pair<bool, boost::filesystem::path>> &files);
const std::vector<std::pair<bool, std::filesystem::path>> &files);
std::string PopulateLayoutWithRTree(storage::BaseDataLayout &layout);
std::vector<std::pair<bool, boost::filesystem::path>> GetUpdatableFiles();
std::vector<std::pair<bool, boost::filesystem::path>> GetStaticFiles();
std::vector<std::pair<bool, std::filesystem::path>> GetUpdatableFiles();
std::vector<std::pair<bool, std::filesystem::path>> GetStaticFiles();
private:
StorageConfig config;
+7 -6
View File
@@ -28,22 +28,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef STORAGE_CONFIG_HPP
#define STORAGE_CONFIG_HPP
#include <boost/filesystem/path.hpp>
#include "storage/io_config.hpp"
#include "osrm/datasets.hpp"
#include <filesystem>
#include <istream>
#include <set>
#include <vector>
namespace osrm::storage
{
std::istream &operator>>(std::istream &in, FeatureDataset &datasets);
static std::vector<boost::filesystem::path>
static std::vector<std::filesystem::path>
GetRequiredFiles(const std::vector<storage::FeatureDataset> &disabled_feature_dataset)
{
std::set<boost::filesystem::path> required{
std::set<std::filesystem::path> required{
".osrm.datasource_names",
".osrm.ebg_nodes",
".osrm.edges",
@@ -82,7 +83,7 @@ GetRequiredFiles(const std::vector<storage::FeatureDataset> &disabled_feature_da
}
}
return std::vector<boost::filesystem::path>(required.begin(), required.end());
return std::vector<std::filesystem::path>(required.begin(), required.end());
;
}
@@ -94,7 +95,7 @@ GetRequiredFiles(const std::vector<storage::FeatureDataset> &disabled_feature_da
struct StorageConfig final : IOConfig
{
StorageConfig(const boost::filesystem::path &base,
StorageConfig(const std::filesystem::path &base,
const std::vector<storage::FeatureDataset> &disabled_feature_datasets_ = {})
: StorageConfig(disabled_feature_datasets_)
{
+6 -6
View File
@@ -7,7 +7,7 @@
#include "util/integer_range.hpp"
#include "util/version.hpp"
#include <boost/filesystem/path.hpp>
#include <filesystem>
extern "C"
{
@@ -19,7 +19,7 @@ namespace osrm::storage::tar
namespace detail
{
inline void
checkMTarError(int error_code, const boost::filesystem::path &filepath, const std::string &name)
checkMTarError(int error_code, const std::filesystem::path &filepath, const std::string &name)
{
switch (error_code)
{
@@ -78,7 +78,7 @@ class FileReader
HasNoFingerprint
};
FileReader(const boost::filesystem::path &path, FingerprintFlag flag) : path(path)
FileReader(const std::filesystem::path &path, FingerprintFlag flag) : path(path)
{
auto ret = mtar_open(&handle, path.string().c_str(), "r");
detail::checkMTarError(ret, path, "");
@@ -204,7 +204,7 @@ class FileReader
return true;
}
boost::filesystem::path path;
std::filesystem::path path;
mtar_t handle;
};
@@ -217,7 +217,7 @@ class FileWriter
HasNoFingerprint
};
FileWriter(const boost::filesystem::path &path, FingerprintFlag flag) : path(path)
FileWriter(const std::filesystem::path &path, FingerprintFlag flag) : path(path)
{
auto ret = mtar_open(&handle, path.string().c_str(), "w");
detail::checkMTarError(ret, path, "");
@@ -305,7 +305,7 @@ class FileWriter
WriteFrom("osrm_fingerprint.meta", fingerprint);
}
boost::filesystem::path path;
std::filesystem::path path;
mtar_t handle;
};
} // namespace osrm::storage::tar
+1 -1
View File
@@ -202,7 +202,7 @@ inline auto make_search_tree_view(const SharedDataIndex &index, const std::strin
const char *path = index.template GetBlockPtr<char>(name + "/file_index_path");
if (!boost::filesystem::exists(boost::filesystem::path{path}))
if (!std::filesystem::exists(std::filesystem::path{path}))
{
throw util::exception("Could not load " + std::string(path) + "Does the leaf file exist?" +
SOURCE_REF);