From 598fa283b80ca5873d7eb0e78195442548c1aa6f Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 24 Jun 2024 18:08:40 +0200 Subject: [PATCH] Treat data file paths as relative to the metadata file The data file paths are actually not native paths but URLs, this covers most cases but not all of them. --- .../libs/ion_gnss_sdr_metadata_standard.cc | 39 ++++++++++--------- .../libs/ion_gnss_sdr_metadata_standard.h | 2 + 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc index 45e3eebbe..3c8f1809d 100644 --- a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc +++ b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc @@ -54,28 +54,29 @@ std::vector GnssMetadataHandler::make_stream_sou { for (const auto& chunk : block.Chunks()) { - for (const auto& lump : chunk.Lumps()) - { - for (const auto& stream : lump.Streams()) - { - if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { - return stream.Id() == it; - })) + for (const auto& lump : chunk.Lumps()) { - auto source = gnss_make_shared( - file, - block, - stream_ids); + for (const auto& stream : lump.Streams()) + { + if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { + return stream.Id() == it; + })) + { + auto source = gnss_make_shared( + metadata_filepath_, + file, + block, + stream_ids); - sources.push_back(source); + sources.push_back(source); - // This file source will take care of any other matching streams in this block - // We can skip the rest of this block - goto next_block; + // This file source will take care of any other matching streams in this block + // We can skip the rest of this block + goto next_block; + } + } } } - } - } next_block: } break; @@ -88,6 +89,7 @@ std::vector GnssMetadataHandler::make_stream_sou IONMetadataStdFileSource::IONMetadataStdFileSource( + const std::filesystem::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, const std::vector& stream_ids) @@ -98,7 +100,8 @@ IONMetadataStdFileSource::IONMetadataStdFileSource( file_metadata_(file), block_metadata_(block) { - fd_ = std::fopen(file.Url().Value().c_str(), "rb"); + std::filesystem::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); + fd_ = std::fopen(data_filepath.c_str(), "rb"); std::size_t block_offset = file.Offset(); std::fseek(fd_, file.Offset() + block_offset + block.SizeHeader(), SEEK_SET); diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h index b97a84576..0543de71d 100644 --- a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h +++ b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h @@ -9,6 +9,7 @@ #include "gnss_block_interface.h" #include #include +#include class chunk_data_t { @@ -268,6 +269,7 @@ public: using sptr = gnss_shared_ptr; IONMetadataStdFileSource( + const std::filesystem::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, const std::vector& stream_ids);