diff --git a/include/util/mmap_tar.hpp b/include/util/mmap_tar.hpp new file mode 100644 index 000000000..b9129ba87 --- /dev/null +++ b/include/util/mmap_tar.hpp @@ -0,0 +1,44 @@ +#ifndef OSRM_UTIL_MMAP_TAR_HPP +#define OSRM_UTIL_MMAP_TAR_HPP + +#include "storage/tar.hpp" + +#include "util/mmap_file.hpp" + +#include + +#include +#include + +namespace osrm +{ +namespace util +{ +using DataRange = std::pair; +using DataMap = std::unordered_map; + +inline DataMap mmapTarFile(const boost::filesystem::path &path, + boost::iostreams::mapped_file_source ®ion) +{ + DataMap map; + + storage::tar::FileReader reader{path, storage::tar::FileReader::VerifyFingerprint}; + + std::vector entries; + reader.List(std::back_inserter(entries)); + + auto raw_file = mmapFile(path, region); + + for (const auto &entry : entries) + { + auto begin = raw_file.data() + entry.offset; + auto end = begin + entry.size; + map[entry.name] = DataRange{begin, end}; + } + + return map; +} +} +} + +#endif diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index ffebb7fcf..bb2a7188d 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -18,6 +18,7 @@ #include "util/for_each_pair.hpp" #include "util/integer_range.hpp" #include "util/log.hpp" +#include "util/mmap_tar.hpp" #include "util/opening_hours.hpp" #include "util/static_graph.hpp" #include "util/static_rtree.hpp" @@ -435,8 +436,13 @@ updateTurnPenalties(const UpdaterConfig &config, // Mapped file pointer for turn indices boost::iostreams::mapped_file_source turn_index_region; - auto turn_index_blocks = util::mmapFile( - config.GetPath(".osrm.turn_penalties_index"), turn_index_region); + const extractor::lookup::TurnIndexBlock *turn_index_blocks; + { + auto map = + util::mmapTarFile(config.GetPath(".osrm.turn_penalties_index"), turn_index_region); + turn_index_blocks = + reinterpret_cast(map["/extractor/turn_index"].first); + } // Get the turn penalty and update to the new value if required std::vector updated_turns;