Use GetPath with file names over accessing member variables
This commit is contained in:
committed by
Daniel J. H
parent
e208485c17
commit
d9e8caf369
@@ -42,23 +42,24 @@ namespace contractor
|
||||
|
||||
struct ContractorConfig final : storage::IOConfig
|
||||
{
|
||||
ContractorConfig() : requested_num_threads(0) {}
|
||||
|
||||
ContractorConfig(const boost::filesystem::path &base) : requested_num_threads(0),
|
||||
IOConfig({".osrm", }, {}, {".osrm.level", ".osrm.core", ".osrm.hsgr", ".osrm.enw"})
|
||||
ContractorConfig()
|
||||
: requested_num_threads(0), IOConfig(
|
||||
{
|
||||
".osrm",
|
||||
},
|
||||
{},
|
||||
{".osrm.level", ".osrm.core", ".osrm.hsgr", ".osrm.enw"})
|
||||
{
|
||||
}
|
||||
|
||||
// Infer the output names from the path of the .osrm file
|
||||
void UseDefaultOutputNames()
|
||||
void UseDefaultOutputNames(const boost::filesystem::path &base)
|
||||
{
|
||||
IOConfig::UseDefaultOutputNames();
|
||||
updater_config.osrm_path = osrm_path;
|
||||
updater_config.UseDefaultOutputNames();
|
||||
IOConfig::UseDefaultOutputNames(base);
|
||||
updater_config.UseDefaultOutputNames(base);
|
||||
}
|
||||
|
||||
// TODO override IsValid to also check updater_config validity
|
||||
// TODO remove direct access to osrm_path to allow passing osrm_path to underlying configs
|
||||
bool IsValid() const { return IOConfig::IsValid() && updater_config.IsValid(); }
|
||||
|
||||
updater::UpdaterConfig updater_config;
|
||||
|
||||
|
||||
@@ -16,16 +16,21 @@ namespace customizer
|
||||
|
||||
struct CustomizationConfig final : storage::IOConfig
|
||||
{
|
||||
CustomizationConfig() : requested_num_threads(0),
|
||||
IOConfig({".osrm", }, {}, {".osrm.ebg", ".osrm.partition", ".osrm.cells", ".osrm.mldgr"})
|
||||
CustomizationConfig()
|
||||
: requested_num_threads(0),
|
||||
IOConfig(
|
||||
{
|
||||
".osrm",
|
||||
},
|
||||
{},
|
||||
{".osrm.ebg", ".osrm.partition", ".osrm.cells", ".osrm.mldgr"})
|
||||
{
|
||||
}
|
||||
|
||||
void UseDefaultOutputNames()
|
||||
void UseDefaultOutputNames(const boost::filesystem::path &base)
|
||||
{
|
||||
IOConfig::UseDefaultOutputNames();
|
||||
updater_config.osrm_path = osrm_path;
|
||||
updater_config.UseDefaultOutputNames();
|
||||
IOConfig::UseDefaultOutputNames(base);
|
||||
updater_config.UseDefaultOutputNames(base);
|
||||
}
|
||||
|
||||
unsigned requested_num_threads;
|
||||
|
||||
@@ -152,9 +152,9 @@ bool Engine<routing_algorithms::ch::Algorithm>::CheckCompability(const EngineCon
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!boost::filesystem::exists(config.storage_config.hsgr_data_path))
|
||||
if (!boost::filesystem::exists(config.storage_config.GetPath(".osrm.hsgr")))
|
||||
return false;
|
||||
storage::io::FileReader in(config.storage_config.hsgr_data_path,
|
||||
storage::io::FileReader in(config.storage_config.GetPath(".osrm.hsgr"),
|
||||
storage::io::FileReader::VerifyFingerprint);
|
||||
|
||||
auto size = in.GetSize();
|
||||
@@ -183,9 +183,9 @@ bool Engine<routing_algorithms::corech::Algorithm>::CheckCompability(const Engin
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!boost::filesystem::exists(config.storage_config.core_data_path))
|
||||
if (!boost::filesystem::exists(config.storage_config.GetPath(".osrm.core")))
|
||||
return false;
|
||||
storage::io::FileReader in(config.storage_config.core_data_path,
|
||||
storage::io::FileReader in(config.storage_config.GetPath(".osrm.core"),
|
||||
storage::io::FileReader::VerifyFingerprint);
|
||||
|
||||
auto size = in.GetSize();
|
||||
@@ -208,9 +208,9 @@ bool Engine<routing_algorithms::mld::Algorithm>::CheckCompability(const EngineCo
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!boost::filesystem::exists(config.storage_config.mld_partition_path))
|
||||
if (!boost::filesystem::exists(config.storage_config.GetPath(".osrm.partition")))
|
||||
return false;
|
||||
storage::io::FileReader in(config.storage_config.mld_partition_path,
|
||||
storage::io::FileReader in(config.storage_config.GetPath(".osrm.partition"),
|
||||
storage::io::FileReader::VerifyFingerprint);
|
||||
|
||||
auto size = in.GetSize();
|
||||
|
||||
@@ -43,36 +43,35 @@ namespace extractor
|
||||
struct ExtractorConfig final : storage::IOConfig
|
||||
{
|
||||
ExtractorConfig() noexcept : requested_num_threads(0),
|
||||
IOConfig({"", }, {}, {".osrm", ".osrm.restrictions", ".osrm.names", ".osrm.tls", ".osrm.tld", ".osrm.timestamp", ".osrm.geometry"
|
||||
, ".osrm.nbg_nodes", ".osrm.ebg_nodes", ".osrm.edges", ".osrm.ebg", ".osrm.ramIndex", ".osrm.fileIndex", ".osrm.turn_duration_penalties"
|
||||
, ".osrm.turn_weight_penalties", ".osrm.turn_penalties_index", ".osrm.enw", ".osrm.properties", ".osrm.icd", ".osrm.cnbg"
|
||||
, ".osrm.cnbg_to_ebg"})
|
||||
IOConfig(
|
||||
{
|
||||
"",
|
||||
},
|
||||
{},
|
||||
{".osrm",
|
||||
".osrm.restrictions",
|
||||
".osrm.names",
|
||||
".osrm.tls",
|
||||
".osrm.tld",
|
||||
".osrm.timestamp",
|
||||
".osrm.geometry",
|
||||
".osrm.nbg_nodes",
|
||||
".osrm.ebg_nodes",
|
||||
".osrm.edges",
|
||||
".osrm.ebg",
|
||||
".osrm.ramIndex",
|
||||
".osrm.fileIndex",
|
||||
".osrm.turn_duration_penalties",
|
||||
".osrm.turn_weight_penalties",
|
||||
".osrm.turn_penalties_index",
|
||||
".osrm.enw",
|
||||
".osrm.properties",
|
||||
".osrm.icd",
|
||||
".osrm.cnbg",
|
||||
".osrm.cnbg_to_ebg"})
|
||||
{
|
||||
}
|
||||
|
||||
void UseDefaultOutputNames()
|
||||
{
|
||||
std::string basepath = input_path.string();
|
||||
|
||||
// TODO move the known_extensions to IsValid
|
||||
auto pos = std::string::npos;
|
||||
std::array<std::string, 5> known_extensions{
|
||||
{".osm.bz2", ".osm.pbf", ".osm.xml", ".pbf", ".osm"}};
|
||||
for (auto ext : known_extensions)
|
||||
{
|
||||
pos = basepath.find(ext);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
basepath.replace(pos, ext.size(), "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
osrm_path = basepath + ".osrm";
|
||||
|
||||
IOConfig::UseDefaultOutputNames();
|
||||
}
|
||||
|
||||
boost::filesystem::path input_path;
|
||||
boost::filesystem::path profile_path;
|
||||
|
||||
|
||||
@@ -97,8 +97,9 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
|
||||
|
||||
if (args[0]->IsString())
|
||||
{
|
||||
engine_config->storage_config = osrm::StorageConfig(
|
||||
*v8::String::Utf8Value(Nan::To<v8::String>(args[0]).ToLocalChecked()));
|
||||
std::string base_path(*v8::String::Utf8Value(args[0]->ToString()));
|
||||
engine_config->storage_config = osrm::StorageConfig();
|
||||
engine_config->storage_config.UseDefaultOutputNames(base_path);
|
||||
engine_config->use_shared_memory = false;
|
||||
return engine_config;
|
||||
}
|
||||
@@ -121,8 +122,9 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
|
||||
|
||||
if (!path->IsUndefined())
|
||||
{
|
||||
engine_config->storage_config =
|
||||
osrm::StorageConfig(*v8::String::Utf8Value(Nan::To<v8::String>(path).ToLocalChecked()));
|
||||
std::string base_path(*v8::String::Utf8Value(path->ToString()));
|
||||
engine_config->storage_config = osrm::StorageConfig();
|
||||
engine_config->storage_config.UseDefaultOutputNames(base_path);
|
||||
engine_config->use_shared_memory = false;
|
||||
}
|
||||
if (!shared_memory->IsUndefined())
|
||||
|
||||
@@ -19,9 +19,12 @@ struct PartitionConfig final : storage::IOConfig
|
||||
: requested_num_threads(0), balance(1.2), boundary_factor(0.25), num_optimizing_cuts(10),
|
||||
small_component_size(1000),
|
||||
max_cell_sizes{128, 128 * 32, 128 * 32 * 16, 128 * 32 * 16 * 32},
|
||||
IOConfig({".osrm", }, {}, {".osrm.ebg", ".osrm.cnbg", ".osrm.cnbg_to_ebg", ".osrm.partition", ".osrm.cells"})
|
||||
{
|
||||
}
|
||||
IOConfig(
|
||||
{".osrm", ".osrm.fileIndex", ".osrm.ebg_nodes"},
|
||||
{".osrm.hsgr", ".osrm.cnbg"},
|
||||
{".osrm.ebg", ".osrm.cnbg", ".osrm.cnbg_to_ebg", ".osrm.partition", ".osrm.cells"})
|
||||
{
|
||||
}
|
||||
|
||||
unsigned requested_num_threads;
|
||||
|
||||
|
||||
+53
-101
@@ -1,8 +1,14 @@
|
||||
#ifndef OSRM_IO_CONFIG_HPP
|
||||
#define OSRM_IO_CONFIG_HPP
|
||||
|
||||
#include "util/exception.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
@@ -11,136 +17,82 @@ namespace 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)
|
||||
: required_input_files(_required_input_files),
|
||||
optional_input_files(_optional_input_files),
|
||||
output_files(_output_files)
|
||||
{}
|
||||
std::vector<boost::filesystem::path> _optional_input_files,
|
||||
std::vector<boost::filesystem::path> _output_files)
|
||||
: required_input_files(_required_input_files), optional_input_files(_optional_input_files),
|
||||
output_files(_output_files)
|
||||
{
|
||||
}
|
||||
|
||||
// Infer the base path from the path of the .osrm file
|
||||
void UseDefaultOutputNames(const boost::filesystem::path &base)
|
||||
{
|
||||
// potentially strip off the .osrm extension for
|
||||
// determining the base path
|
||||
const std::string ext = ".osrm";
|
||||
const auto pos = base.find(ext);
|
||||
if (pos != std::string::npos)
|
||||
// potentially strip off the .osrm (or other) extensions for
|
||||
// determining the base path=
|
||||
std::string path = base.string();
|
||||
|
||||
std::array<std::string, 6> known_extensions{
|
||||
{".osm.bz2", ".osm.pbf", ".osm.xml", ".pbf", ".osm", ".osrm"}};
|
||||
for (auto ext : known_extensions)
|
||||
{
|
||||
base.replace(pos, ext.size(), "");
|
||||
}
|
||||
else
|
||||
{
|
||||
// unknown extension or no extension
|
||||
const auto pos = path.find(ext);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
path.replace(pos, ext.size(), "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
base_path = base;
|
||||
base_path = {path};
|
||||
}
|
||||
|
||||
bool IsValid()
|
||||
bool IsValid() const
|
||||
{
|
||||
bool success = true;
|
||||
for (auto &path : required_input_files)
|
||||
for (auto &fileName : required_input_files)
|
||||
{
|
||||
if (!boost::filesystem::is_regular_file(path))
|
||||
if (!boost::filesystem::is_regular_file({base_path.string() + fileName.string()}))
|
||||
{
|
||||
util::Log(logWARNING) << "Missing/Broken File: " << path.string();
|
||||
util::Log(logWARNING) << "Missing/Broken File: " << base_path.string()
|
||||
<< fileName.string();
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
boost::filesystem::path GetPath(const std::string &fileName)
|
||||
boost::filesystem::path GetPath(const std::string &fileName) const
|
||||
{
|
||||
if(!IsConfigured(fileName, required_input_files)
|
||||
&& !IsConfigured(fileName, optional_input_files)
|
||||
&& !IsConfigured(fileName, output_files)) {
|
||||
util::Log(logERROR) << "Missing File: " << fileName;
|
||||
return 0; // TODO throw
|
||||
if (!IsConfigured(fileName, required_input_files) &&
|
||||
!IsConfigured(fileName, optional_input_files) && !IsConfigured(fileName, output_files))
|
||||
{
|
||||
util::Log(logERROR) << "Tried to access file which is not configured: " << fileName;
|
||||
throw util::exception("Tried to access file which is not configured: " + fileName);
|
||||
}
|
||||
|
||||
return { base_path.string() + fileName };
|
||||
return {base_path.string() + fileName};
|
||||
}
|
||||
|
||||
private:
|
||||
bool IsConfigured(const std::string &fileName, const std::vector<boost::filesystem::path> &paths) {
|
||||
for (auto &path : paths) {
|
||||
if(boost::algorithm::ends_with(path.string(), fileName)) {
|
||||
boost::filesystem::path base_path;
|
||||
|
||||
private:
|
||||
static bool IsConfigured(const std::string &fileName,
|
||||
const std::vector<boost::filesystem::path> &paths)
|
||||
{
|
||||
for (auto &path : paths)
|
||||
{
|
||||
if (boost::algorithm::ends_with(path.string(), fileName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<boost::filesystem::path> required_input_files;
|
||||
std::vector<boost::filesystem::path> optional_input_files;
|
||||
std::vector<boost::filesystem::path> output_files;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
boost::filesystem::path base_path;
|
||||
|
||||
ram_index_path = {osrm_path.string() + ".ramIndex"};
|
||||
file_index_path = {osrm_path.string() + ".fileIndex"};
|
||||
hsgr_data_path = {osrm_path.string() + ".hsgr"};
|
||||
nodes_data_path = {osrm_path.string() + ".nodes"};
|
||||
edges_data_path = {osrm_path.string() + ".edges"};
|
||||
core_data_path = {osrm_path.string() + ".core"};
|
||||
geometries_path = {osrm_path.string() + ".geometry"};
|
||||
timestamp_path = {osrm_path.string() + ".timestamp"};
|
||||
turn_weight_penalties_path = {osrm_path.string() + ".turn_weight_penalties"};
|
||||
turn_duration_penalties_path = {osrm_path.string() + ".turn_duration_penalties"};
|
||||
turn_penalties_index_path = {osrm_path.string() + ".turn_penalties_index"};
|
||||
datasource_names_path = {osrm_path.string() + ".datasource_names"};
|
||||
names_data_path = {osrm_path.string() + ".names"};
|
||||
properties_path = {osrm_path.string() + ".properties"};
|
||||
intersection_class_path = {osrm_path.string() + ".icd"};
|
||||
turn_lane_data_path = {osrm_path.string() + ".tld"};
|
||||
turn_lane_description_path = {osrm_path.string() + ".tls"};
|
||||
mld_partition_path = {osrm_path.string() + ".partition"};
|
||||
mld_storage_path = {osrm_path.string() + ".cells"};
|
||||
mld_graph_path = {osrm_path.string() + ".mldgr"};
|
||||
level_path = {osrm_path.string() + ".level"};
|
||||
node_path = {osrm_path.string() + ".enw"};
|
||||
edge_based_nodes_data_path = {osrm_path.string() + ".ebg_nodes"};
|
||||
node_based_nodes_data_path = {osrm_path.string() + ".nbg_nodes"};
|
||||
edge_based_graph_path = {osrm_path.string() + ".ebg"};
|
||||
compressed_node_based_graph_path = {osrm_path.string() + ".cnbg"};
|
||||
cnbg_ebg_mapping_path = {osrm_path.string() + ".cnbg_to_ebg"};
|
||||
turn_restrictions_path = {osrm_path.string() + ".restrictions"};
|
||||
intersection_class_data_path = {osrm_path.string() + ".icd"};
|
||||
*/
|
||||
|
||||
boost::filesystem::path osrm_path;
|
||||
boost::filesystem::path ram_index_path;
|
||||
boost::filesystem::path file_index_path;
|
||||
boost::filesystem::path hsgr_data_path;
|
||||
boost::filesystem::path nodes_data_path;
|
||||
boost::filesystem::path edges_data_path;
|
||||
boost::filesystem::path core_data_path;
|
||||
boost::filesystem::path geometries_path;
|
||||
boost::filesystem::path timestamp_path;
|
||||
boost::filesystem::path turn_weight_penalties_path;
|
||||
boost::filesystem::path turn_duration_penalties_path;
|
||||
boost::filesystem::path turn_penalties_index_path;
|
||||
boost::filesystem::path datasource_names_path;
|
||||
boost::filesystem::path datasource_indexes_path;
|
||||
boost::filesystem::path names_data_path;
|
||||
boost::filesystem::path properties_path;
|
||||
boost::filesystem::path intersection_class_path;
|
||||
boost::filesystem::path turn_lane_data_path;
|
||||
boost::filesystem::path turn_lane_description_path;
|
||||
boost::filesystem::path mld_partition_path;
|
||||
boost::filesystem::path mld_storage_path;
|
||||
boost::filesystem::path mld_graph_path;
|
||||
boost::filesystem::path level_path;
|
||||
boost::filesystem::path node_path;
|
||||
boost::filesystem::path edge_based_nodes_data_path;
|
||||
boost::filesystem::path node_based_nodes_data_path;
|
||||
boost::filesystem::path edge_based_graph_path;
|
||||
boost::filesystem::path compressed_node_based_graph_path;
|
||||
boost::filesystem::path cnbg_ebg_mapping_path;
|
||||
boost::filesystem::path turn_restrictions_path;
|
||||
boost::filesystem::path intersection_class_data_path;
|
||||
std::vector<boost::filesystem::path> required_input_files;
|
||||
std::vector<boost::filesystem::path> optional_input_files;
|
||||
std::vector<boost::filesystem::path> output_files;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,20 +44,31 @@ namespace storage
|
||||
*/
|
||||
struct StorageConfig final : IOConfig
|
||||
{
|
||||
StorageConfig() :
|
||||
IOConfig({".osrm.ramIndex", ".osrm.fileIndex", ".osrm.hsgr", ".osrm.nodes", ".osrm.edges", ".osrm.core",
|
||||
".osrm.geometry", ".osrm.timestamp", ".osrm.turn_weight_penalties", ".osrm.turn_duration_penalties", ".osrm.turn_penalties_index", ".osrm.datasource_names",
|
||||
".osrm.names", ".osrm.properties", ".osrm.icd", ".osrm.tld", ".osrm.tls", ".osrm.partition", ".osrm.cells", ".osrm.mldgr"}, {}, {})
|
||||
StorageConfig()
|
||||
: IOConfig({".osrm.ramIndex",
|
||||
".osrm.fileIndex",
|
||||
".osrm.edges",
|
||||
".osrm.geometry",
|
||||
".osrm.timestamp",
|
||||
".osrm.turn_weight_penalties",
|
||||
".osrm.turn_duration_penalties",
|
||||
".osrm.datasource_names",
|
||||
".osrm.names",
|
||||
".osrm.properties",
|
||||
".osrm.icd"},
|
||||
{".osrm.hsgr",
|
||||
".osrm.nodes",
|
||||
".osrm.nbg_nodes",
|
||||
".osrm.ebg_nodes",
|
||||
".osrm.core",
|
||||
".osrm.cells",
|
||||
".osrm.mldgr",
|
||||
".osrm.tld",
|
||||
".osrm.tls",
|
||||
".osrm.partition"},
|
||||
{})
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a storage configuration setting paths based on a base path.
|
||||
*
|
||||
* \param base The base path (e.g. france.pbf.osrm) to derive auxiliary file suffixes from.
|
||||
*/
|
||||
StorageConfig(const boost::filesystem::path &base) : IOConfig(base) {}
|
||||
bool IsValid() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,26 @@ namespace updater
|
||||
|
||||
struct UpdaterConfig final : storage::IOConfig
|
||||
{
|
||||
UpdaterConfig() {}
|
||||
UpdaterConfig(const boost::filesystem::path &base) : IOConfig(
|
||||
{ ".osrm.ebg", ".osrm.turn_weight_penalties", ".osrm.turn_duration_penalties", ".osrm.turn_penalties_index", ".osrm.nbg_nodes", ".osrm.ebg_nodes",
|
||||
".osrm.edges", ".osrm.geometry", ".osrm.fileIndex", ".osrm.datasource_names", ".osrm.properties", ".osrm.restrictions", }, {}, {}
|
||||
) {}
|
||||
UpdaterConfig()
|
||||
: IOConfig(
|
||||
{
|
||||
".osrm.ebg",
|
||||
".osrm.turn_weight_penalties",
|
||||
".osrm.turn_duration_penalties",
|
||||
".osrm.turn_penalties_index",
|
||||
".osrm.nbg_nodes",
|
||||
".osrm.ebg_nodes",
|
||||
".osrm.edges",
|
||||
".osrm.geometry",
|
||||
".osrm.fileIndex",
|
||||
".osrm.datasource_names",
|
||||
".osrm.properties",
|
||||
".osrm.restrictions",
|
||||
},
|
||||
{},
|
||||
{})
|
||||
{
|
||||
}
|
||||
|
||||
double log_edge_updates_factor;
|
||||
std::time_t valid_now;
|
||||
|
||||
Reference in New Issue
Block a user