implement proper checks for conflicting inputs
This commit is contained in:
parent
2e4ff30103
commit
4028c0b24f
@ -44,6 +44,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
void AssertPathExists(const boost::filesystem::path& path)
|
||||||
|
{
|
||||||
|
if (!boost::filesystem::is_regular_file(path))
|
||||||
|
{
|
||||||
|
SimpleLogger().Write(logDEBUG) << path << " check failed";
|
||||||
|
throw OSRMException(path.string() + " not found.");
|
||||||
|
} else {
|
||||||
|
SimpleLogger().Write(logDEBUG) << path << " exists";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// support old capitalized option names by down-casing them with a regex replace
|
// support old capitalized option names by down-casing them with a regex replace
|
||||||
inline void PrepareConfigFile(
|
inline void PrepareConfigFile(
|
||||||
@ -60,14 +70,9 @@ inline void PrepareConfigFile(
|
|||||||
output = boost::regex_replace( input_str, regex, format );
|
output = boost::regex_replace( input_str, regex, format );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// generate boost::program_options object for the routing part
|
// generate boost::program_options object for the routing part
|
||||||
inline bool GenerateDataStoreOptions(
|
inline bool GenerateDataStoreOptions(const int argc, const char * argv[], ServerPaths & paths)
|
||||||
const int argc,
|
{
|
||||||
const char * argv[],
|
|
||||||
ServerPaths & paths
|
|
||||||
) {
|
|
||||||
|
|
||||||
// declare a group of options that will be allowed only on command line
|
// declare a group of options that will be allowed only on command line
|
||||||
boost::program_options::options_description generic_options("Options");
|
boost::program_options::options_description generic_options("Options");
|
||||||
generic_options.add_options()
|
generic_options.add_options()
|
||||||
@ -100,11 +105,11 @@ inline bool GenerateDataStoreOptions(
|
|||||||
boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
|
boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
|
||||||
".edges file"
|
".edges file"
|
||||||
)
|
)
|
||||||
(
|
// (
|
||||||
"geometry",
|
// "geometry",
|
||||||
boost::program_options::value<boost::filesystem::path>(&paths["geometries"]),
|
// boost::program_options::value<boost::filesystem::path>(&paths["geometries"]),
|
||||||
".geometry file"
|
// ".geometry file"
|
||||||
)
|
// )
|
||||||
(
|
(
|
||||||
"ramindex",
|
"ramindex",
|
||||||
boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
|
boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
|
||||||
@ -113,7 +118,7 @@ inline bool GenerateDataStoreOptions(
|
|||||||
(
|
(
|
||||||
"fileindex",
|
"fileindex",
|
||||||
boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
|
boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
|
||||||
"File index file"
|
".fileIndex file"
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
"namesdata",
|
"namesdata",
|
||||||
@ -148,38 +153,64 @@ inline bool GenerateDataStoreOptions(
|
|||||||
config_file_options.add(config_options).add(hidden_options);
|
config_file_options.add(config_options).add(hidden_options);
|
||||||
|
|
||||||
boost::program_options::options_description visible_options(
|
boost::program_options::options_description visible_options(
|
||||||
boost::filesystem::basename(argv[0]) + " <base.osrm> [<options>]"
|
boost::filesystem::basename(argv[0]) + " [<options>] <configuration>"
|
||||||
);
|
);
|
||||||
visible_options.add(generic_options).add(config_options);
|
visible_options.add(generic_options).add(config_options);
|
||||||
|
|
||||||
// parse command line options
|
// parse command line options
|
||||||
boost::program_options::variables_map option_variables;
|
boost::program_options::variables_map option_variables;
|
||||||
boost::program_options::store(
|
boost::program_options::store
|
||||||
|
(
|
||||||
boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(positional_options).run(),
|
boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(positional_options).run(),
|
||||||
option_variables
|
option_variables
|
||||||
);
|
);
|
||||||
|
|
||||||
if(option_variables.count("version")) {
|
if(option_variables.count("version"))
|
||||||
|
{
|
||||||
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(option_variables.count("help")) {
|
if(option_variables.count("help"))
|
||||||
|
{
|
||||||
SimpleLogger().Write() << visible_options;
|
SimpleLogger().Write() << visible_options;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::program_options::notify(option_variables);
|
boost::program_options::notify(option_variables);
|
||||||
|
|
||||||
|
const bool parameter_present =
|
||||||
|
(paths.find("hsgrdata") != paths.end() && !paths.find("hsgrdata")->second.string().empty() ) ||
|
||||||
|
(paths.find("nodesdata") != paths.end() && !paths.find("nodesdata")->second.string().empty()) ||
|
||||||
|
(paths.find("edgesdata") != paths.end() && !paths.find("edgesdata")->second.string().empty()) ||
|
||||||
|
// (paths.find("geometry") != paths.end() && !paths.find("geometry")->second.string().empty())) ||
|
||||||
|
(paths.find("ramindex") != paths.end() && !paths.find("ramindex")->second.string().empty()) ||
|
||||||
|
(paths.find("fileindex") != paths.end() && !paths.find("fileindex")->second.string().empty()) ||
|
||||||
|
(paths.find("timestamp") != paths.end() && !paths.find("timestamp")->second.string().empty()) ;
|
||||||
|
|
||||||
|
if (parameter_present)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
( paths.find("config") != paths.end() &&
|
||||||
|
boost::filesystem::is_regular_file(paths.find("config")->second)
|
||||||
|
) || option_variables.count("base")
|
||||||
|
)
|
||||||
|
{
|
||||||
|
SimpleLogger().Write(logWARNING) << "conflicting parameters";
|
||||||
|
SimpleLogger().Write() << visible_options;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// parse config file
|
// parse config file
|
||||||
ServerPaths::iterator path_iterator = paths.find("config");
|
ServerPaths::iterator path_iterator = paths.find("config");
|
||||||
if (
|
if (
|
||||||
path_iterator != paths.end() &&
|
path_iterator != paths.end() &&
|
||||||
boost::filesystem::is_regular_file(path_iterator->second) &&
|
boost::filesystem::is_regular_file(path_iterator->second) &&
|
||||||
!option_variables.count("base")
|
!option_variables.count("base")
|
||||||
) {
|
)
|
||||||
SimpleLogger().Write() <<
|
{
|
||||||
"Reading options from: " << path_iterator->second.string();
|
SimpleLogger().Write() << "Reading options from: " << path_iterator->second.string();
|
||||||
std::string config_str;
|
std::string config_str;
|
||||||
PrepareConfigFile( path_iterator->second, config_str );
|
PrepareConfigFile( path_iterator->second, config_str );
|
||||||
std::stringstream config_stream( config_str );
|
std::stringstream config_stream( config_str );
|
||||||
@ -189,101 +220,117 @@ inline bool GenerateDataStoreOptions(
|
|||||||
);
|
);
|
||||||
boost::program_options::notify(option_variables);
|
boost::program_options::notify(option_variables);
|
||||||
}
|
}
|
||||||
|
else if (option_variables.count("base"))
|
||||||
if( option_variables.count("base") ) {
|
{
|
||||||
path_iterator = paths.find("base");
|
path_iterator = paths.find("base");
|
||||||
BOOST_ASSERT( paths.end() != path_iterator );
|
BOOST_ASSERT( paths.end() != path_iterator );
|
||||||
std::string base_string = path_iterator->second.string();
|
std::string base_string = path_iterator->second.string();
|
||||||
|
|
||||||
path_iterator = paths.find("hsgrdata");
|
path_iterator = paths.find("hsgrdata");
|
||||||
if(
|
if (path_iterator != paths.end())
|
||||||
path_iterator != paths.end() &&
|
{
|
||||||
!boost::filesystem::is_regular_file(path_iterator->second)
|
|
||||||
) {
|
|
||||||
path_iterator->second = base_string + ".hsgr";
|
path_iterator->second = base_string + ".hsgr";
|
||||||
} else {
|
|
||||||
throw OSRMException(base_string + ".hsgr not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path_iterator = paths.find("nodesdata");
|
path_iterator = paths.find("nodesdata");
|
||||||
if(
|
if (path_iterator != paths.end())
|
||||||
path_iterator != paths.end() &&
|
{
|
||||||
!boost::filesystem::is_regular_file(path_iterator->second)
|
|
||||||
) {
|
|
||||||
path_iterator->second = base_string + ".nodes";
|
path_iterator->second = base_string + ".nodes";
|
||||||
} else {
|
|
||||||
throw OSRMException(base_string + ".nodes not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
path_iterator = paths.find("edgesdata");
|
path_iterator = paths.find("edgesdata");
|
||||||
if(
|
if (path_iterator != paths.end())
|
||||||
path_iterator != paths.end() &&
|
{
|
||||||
!boost::filesystem::is_regular_file(path_iterator->second)
|
|
||||||
) {
|
|
||||||
path_iterator->second = base_string + ".edges";
|
path_iterator->second = base_string + ".edges";
|
||||||
} else {
|
|
||||||
throw OSRMException(base_string + ".edges not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
path_iterator = paths.find("geometries");
|
|
||||||
if(
|
|
||||||
path_iterator != paths.end() &&
|
|
||||||
!boost::filesystem::is_regular_file(path_iterator->second)
|
|
||||||
) {
|
|
||||||
path_iterator->second = base_string + ".geometry";
|
|
||||||
} else {
|
|
||||||
throw OSRMException(base_string + ".geometry not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// path_iterator = paths.find("geometries");
|
||||||
|
// if (path_iterator != paths.end())
|
||||||
|
// {
|
||||||
|
// path_iterator->second = base_string + ".geometry";
|
||||||
|
// }
|
||||||
|
|
||||||
path_iterator = paths.find("ramindex");
|
path_iterator = paths.find("ramindex");
|
||||||
if(
|
if (path_iterator != paths.end())
|
||||||
path_iterator != paths.end() &&
|
{
|
||||||
!boost::filesystem::is_regular_file(path_iterator->second)
|
|
||||||
) {
|
|
||||||
path_iterator->second = base_string + ".ramIndex";
|
path_iterator->second = base_string + ".ramIndex";
|
||||||
} else {
|
|
||||||
throw OSRMException(base_string + ".ramIndex not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
path_iterator = paths.find("fileindex");
|
path_iterator = paths.find("fileindex");
|
||||||
if(
|
if (path_iterator != paths.end())
|
||||||
path_iterator != paths.end() &&
|
{
|
||||||
!boost::filesystem::is_regular_file(path_iterator->second)
|
|
||||||
) {
|
|
||||||
path_iterator->second = base_string + ".fileIndex";
|
path_iterator->second = base_string + ".fileIndex";
|
||||||
} else {
|
|
||||||
throw OSRMException(base_string + ".fileIndex not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
path_iterator = paths.find("namesdata");
|
path_iterator = paths.find("namesdata");
|
||||||
if(
|
if (path_iterator != paths.end())
|
||||||
path_iterator != paths.end() &&
|
{
|
||||||
!boost::filesystem::is_regular_file(path_iterator->second)
|
|
||||||
) {
|
|
||||||
path_iterator->second = base_string + ".names";
|
path_iterator->second = base_string + ".names";
|
||||||
} else {
|
|
||||||
throw OSRMException(base_string + ".namesIndex not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path_iterator = paths.find("timestamp");
|
path_iterator = paths.find("timestamp");
|
||||||
if(
|
if (path_iterator != paths.end())
|
||||||
path_iterator != paths.end() &&
|
{
|
||||||
!boost::filesystem::is_regular_file(path_iterator->second)
|
|
||||||
) {
|
|
||||||
path_iterator->second = base_string + ".timestamp";
|
path_iterator->second = base_string + ".timestamp";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path_iterator = paths.find("hsgrdata");
|
||||||
|
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||||
|
{
|
||||||
|
throw OSRMException(".hsgr file must be specified");
|
||||||
|
}
|
||||||
|
AssertPathExists(path_iterator->second);
|
||||||
|
|
||||||
|
path_iterator = paths.find("nodesdata");
|
||||||
|
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||||
|
{
|
||||||
|
throw OSRMException(".nodes file must be specified");
|
||||||
|
}
|
||||||
|
AssertPathExists(path_iterator->second);
|
||||||
|
|
||||||
|
path_iterator = paths.find("edgesdata");
|
||||||
|
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||||
|
{
|
||||||
|
throw OSRMException(".edges file must be specified");
|
||||||
|
}
|
||||||
|
AssertPathExists(path_iterator->second);
|
||||||
|
|
||||||
|
// path_iterator = paths.find("geometries");
|
||||||
|
// if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||||
|
// {
|
||||||
|
// path_iterator->second = base_string + ".geometry";
|
||||||
|
// }
|
||||||
|
// AssertPathExists(path_iterator->second);
|
||||||
|
|
||||||
|
path_iterator = paths.find("ramindex");
|
||||||
|
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||||
|
{
|
||||||
|
throw OSRMException(".ramindex file must be specified");
|
||||||
|
}
|
||||||
|
AssertPathExists(path_iterator->second);
|
||||||
|
|
||||||
|
path_iterator = paths.find("fileindex");
|
||||||
|
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||||
|
{
|
||||||
|
throw OSRMException(".fileindex file must be specified");
|
||||||
|
}
|
||||||
|
AssertPathExists(path_iterator->second);
|
||||||
|
|
||||||
|
path_iterator = paths.find("namesdata");
|
||||||
|
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||||
|
{
|
||||||
|
throw OSRMException(".names file must be specified");
|
||||||
|
}
|
||||||
|
AssertPathExists(path_iterator->second);
|
||||||
|
|
||||||
|
path_iterator = paths.find("timestamp");
|
||||||
|
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||||
|
{
|
||||||
|
throw OSRMException(".timestamp file must be specified");
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleLogger().Write() << visible_options;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* DATA_STORE_OPTIONS_H */
|
#endif /* DATA_STORE_OPTIONS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user