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 f2a86cd commit a06e1c1
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

4 comments on commit a06e1c1

@emiltin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that new regex machanism looks a bit complicated. what was causing the original version to fail?

are you sure "\w+=" covers all cases, for example leading whitespace?

@DennisOSRM
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main issue here is the incomplete regex implementation in GCC 4.7 and 4.8. Working around that.

@emiltin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see.
but check that your regex works as expected. it seems you're looking only for alphanumerics directly followed by an equal sign, which would not match if there's space before the '='. and since you're not using an anchor, you will also potentially downcase values if they match?

Threads=4                          # ok
Threads = 4                        # is this downcased?
 Threads = 4                       # is this downcased?
file="/mypath/ABC=.osrm"           # is the file name downcased?

@DennisOSRM
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reverted the code to the prev boost based regex with 3f7982a as GCC does not properly implement the stuff prior to GCC v4.9

Please sign in to comment.