Skip to content

Commit

Permalink
Propagate "custom_data" and "ros_distro" in to the metadata.yaml file…
Browse files Browse the repository at this point in the history
… during re-indexing (#1700)

* propagate custom data and ros_distro during reindexing
Signed-off-by: Cole Tucker

Signed-off-by: coalman321 <cjtucker321@gmail.com>

* fix ament uncrustify issue

Signed-off-by: coalman321 <cjtucker321@gmail.com>

* only update metadata if size is nonzero

Signed-off-by: coalman321 <cjtucker321@gmail.com>

* fix uncrustify issue and switch to empty

Signed-off-by: coalman321 <cjtucker321@gmail.com>

* update reindexer test to verify custom data and ros_distro changes

Signed-off-by: coalman321 <cjtucker321@gmail.com>

* Convert to use exact clock type for windows CI

Signed-off-by: coalman321 <cjtucker321@gmail.com>

---------

Signed-off-by: coalman321 <cjtucker321@gmail.com>
  • Loading branch information
coalman321 committed Jun 12, 2024
1 parent e7e6005 commit 804432c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rosbag2_cpp/src/rosbag2_cpp/reindexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ void Reindexer::aggregate_metadata(
const rosbag2_storage::StorageOptions & storage_options)
{
std::map<std::string, rosbag2_storage::TopicInformation> temp_topic_info;
std::chrono::time_point<std::chrono::high_resolution_clock> latest_log_start =
std::chrono::time_point<std::chrono::high_resolution_clock>::min();

// In order to most accurately reconstruct the metadata, we need to
// visit each of the contained relative files files in the bag,
Expand All @@ -188,6 +190,17 @@ void Reindexer::aggregate_metadata(
auto temp_metadata = bag_reader->get_metadata();
metadata_.storage_identifier = temp_metadata.storage_identifier;

// try to find the last log for the most complete custom data section
if (latest_log_start < temp_metadata.starting_time) {
latest_log_start = temp_metadata.starting_time;
if (!temp_metadata.custom_data.empty()) {
metadata_.custom_data = temp_metadata.custom_data;
}
if (!temp_metadata.ros_distro.empty()) {
metadata_.ros_distro = temp_metadata.ros_distro;
}
}

if (temp_metadata.starting_time < metadata_.starting_time) {
metadata_.starting_time = temp_metadata.starting_time;
}
Expand Down
3 changes: 3 additions & 0 deletions rosbag2_tests/test/rosbag2_tests/test_reindexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ReindexTestFixture : public ParametrizedTemporaryDirectoryFixture
rosbag2_storage::StorageOptions storage_options;
storage_options.storage_id = GetParam();
storage_options.uri = root_bag_path_.string();
storage_options.custom_data["name"] = "value";
writer.open(storage_options);
rosbag2_storage::TopicMetadata topic;
topic.name = "/test_topic";
Expand Down Expand Up @@ -132,6 +133,8 @@ TEST_P(ReindexTestFixture, test_multiple_files) {

EXPECT_EQ(generated_metadata.storage_identifier, GetParam());
EXPECT_EQ(generated_metadata.version, target_metadata.version);
EXPECT_EQ(generated_metadata.ros_distro, target_metadata.ros_distro);
EXPECT_EQ(generated_metadata.custom_data, target_metadata.custom_data);

for (const auto & gen_rel_path : generated_metadata.relative_file_paths) {
EXPECT_TRUE(
Expand Down

0 comments on commit 804432c

Please sign in to comment.