@@ -16,27 +16,33 @@ namespace fs = std::filesystem;
1616namespace nigiri {
1717
1818shapes_storage::shapes_storage (std::filesystem::path path,
19- cista::mmap::protection const mode)
19+ cista::mmap::protection const mode,
20+ bool keep_shape_data)
2021 : mode_{mode},
2122 p_{[&]() {
2223 fs::create_directories (path);
2324 return std::move (path);
2425 }()},
2526 data_{mm_paged_vecvec_helper<shape_idx_t , geo::latlng>::data_t {
26- mm_vec<geo::latlng>{mm (" shapes_data.bin" )}},
27+ mm_vec<geo::latlng>{mm (" shapes_data.bin" , keep_shape_data )}},
2728 mm_vec<cista::page<std::uint64_t , std::uint32_t >>{
28- mm (" shapes_idx.bin" )}},
29+ mm (" shapes_idx.bin" , keep_shape_data )}},
2930 offsets_{mm_vec<shape_offset_t >{mm (" shape_offsets_data.bin" )},
3031 mm_vec<std::uint64_t >{mm (" shape_offsets_idx.bin" )}},
3132 trip_offset_indices_{mm (" shape_trip_offsets.bin" )},
3233 route_bboxes_{mm (" shape_route_bboxes.bin" )},
3334 route_segment_bboxes_{
3435 mm_vec<geo::box>{mm (" shape_route_segment_bboxes_data.bin" )},
3536 mm_vec<std::uint64_t >{mm (" shape_route_segment_bboxes_idx.bin" )}},
36- shape_sources_{mm (" shape_sources.bin" )} {}
37-
38- cista::mmap shapes_storage::mm (char const * file) {
39- return cista::mmap{(p_ / file).generic_string ().c_str (), mode_};
37+ shape_sources_{mm (" shape_sources.bin" , keep_shape_data)} {}
38+
39+ cista::mmap shapes_storage::mm (char const * file, bool const keep) {
40+ auto const p = (p_ / file);
41+ return cista::mmap{
42+ p.generic_string ().c_str (),
43+ keep && mode_ == cista::mmap::protection::WRITE && fs::exists (p)
44+ ? cista::mmap::protection::MODIFY
45+ : mode_};
4046}
4147
4248std::tuple<std::span<geo::latlng const >, shape_idx_t , shape_offset_idx_t >
0 commit comments