Skip to content

Commit

Permalink
fix #1021, always check if files exist
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisOSRM committed May 20, 2014
1 parent 4fc329a commit 4ec9f2c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
15 changes: 11 additions & 4 deletions Server/DataStructures/InternalDataFacade.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
if (boost::filesystem::exists(timestamp_path))
{
SimpleLogger().Write() << "Loading Timestamp";
boost::filesystem::ifstream timestampInStream(timestamp_path);
if (!timestampInStream)
boost::filesystem::ifstream timestamp_stream(timestamp_path);
if (!timestamp_stream)
{
SimpleLogger().Write(logWARNING) << timestamp_path << " not found";
}
getline(timestampInStream, m_timestamp);
timestampInStream.close();
getline(timestamp_stream, m_timestamp);
timestamp_stream.close();
}
if (m_timestamp.empty())
{
Expand Down Expand Up @@ -279,16 +279,23 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge

// load data
SimpleLogger().Write() << "loading graph data";
AssertPathExists(hsgr_path);
LoadGraph(hsgr_path);
SimpleLogger().Write() << "loading egde information";
AssertPathExists(nodes_data_path);
AssertPathExists(edges_data_path);
LoadNodeAndEdgeInformation(nodes_data_path, edges_data_path);
SimpleLogger().Write() << "loading geometries";
AssertPathExists(geometries_path);
LoadGeometries(geometries_path);
SimpleLogger().Write() << "loading r-tree";
AssertPathExists(ram_index_path);
AssertPathExists(file_index_path);
LoadRTree(ram_index_path, file_index_path);
SimpleLogger().Write() << "loading timestamp";
LoadTimestamp(timestamp_path);
SimpleLogger().Write() << "loading street names";
AssertPathExists(names_data_path);
LoadStreetNames(names_data_path);
}

Expand Down
18 changes: 15 additions & 3 deletions Util/IniFileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef INI_FILE_UTIL_H
#define INI_FILE_UTIL_H

#include "SimpleLogger.h"

#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>

Expand All @@ -40,9 +42,19 @@ inline std::string ReadIniFileAndLowerContents(const boost::filesystem::path &pa
boost::filesystem::fstream config_stream(path);
std::string input_str((std::istreambuf_iterator<char>(config_stream)),
std::istreambuf_iterator<char>());
std::regex regex("^([^=]*)"); // match from start of line to '='
std::string format("\\L$1\\E"); // replace with downcased substring
return std::regex_replace(input_str, regex, format);
std::regex regex("\\w+=");

std::string output = input_str;
const std::sregex_token_iterator end;
for (std::sregex_token_iterator i(input_str.begin(), input_str.end(), regex); i != end; ++i)
{
std::string match = *i;
std::string new_regex = *i;
std::transform(new_regex.begin(), new_regex.end(), new_regex.begin(), ::tolower);
SimpleLogger().Write() << match << " - " << new_regex;
output = std::regex_replace(output, std::regex(match), new_regex);
}
return output;
}

#endif // INI_FILE_UTIL_H
3 changes: 3 additions & 0 deletions Util/ProgramOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ inline unsigned GenerateServerProgramOptions(const int argc,

// parse config file
ServerPaths::iterator path_iterator = paths.find("config");
bool use_ini_file = false;
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
!option_variables.count("base"))
{
Expand All @@ -159,6 +160,8 @@ inline unsigned GenerateServerProgramOptions(const int argc,
boost::program_options::store(parse_config_file(config_stream, config_file_options),
option_variables);
boost::program_options::notify(option_variables);
use_ini_file = true;
return INIT_OK_START_ENGINE;
}

if (1 > requested_num_threads)
Expand Down

0 comments on commit 4ec9f2c

Please sign in to comment.