Skip to content

Commit 74eceb0

Browse files
committed
Bugfix: Update metadata with new file_info before saving it first time
Signed-off-by: Michael Orlov <[email protected]>
1 parent cb7d362 commit 74eceb0

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Diff for: rosbag2_cpp/src/rosbag2_cpp/writers/sequential_writer.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ void SequentialWriter::switch_to_next_storage()
332332

333333
throw std::runtime_error(errmsg.str());
334334
}
335+
336+
rosbag2_storage::FileInformation file_info{};
337+
file_info.starting_time =
338+
std::chrono::time_point<std::chrono::high_resolution_clock>(std::chrono::nanoseconds::max());
339+
file_info.path = strip_parent_path(storage_->get_relative_file_path());
340+
metadata_.files.push_back(file_info);
341+
metadata_.relative_file_paths.push_back(file_info.path);
342+
335343
storage_->update_metadata(metadata_);
336344
// Re-register all topics since we rolled-over to a new bagfile.
337345
for (const auto & topic : topics_names_to_info_) {
@@ -351,14 +359,6 @@ std::string SequentialWriter::split_bagfile_local(bool execute_callbacks)
351359
switch_to_next_storage();
352360
auto opened_file = storage_->get_relative_file_path();
353361

354-
metadata_.relative_file_paths.push_back(strip_parent_path(storage_->get_relative_file_path()));
355-
356-
rosbag2_storage::FileInformation file_info{};
357-
file_info.starting_time = std::chrono::time_point<std::chrono::high_resolution_clock>(
358-
std::chrono::nanoseconds::max());
359-
file_info.path = strip_parent_path(storage_->get_relative_file_path());
360-
metadata_.files.push_back(file_info);
361-
362362
if (execute_callbacks) {
363363
execute_bag_split_callbacks(closed_file, opened_file);
364364
}

Diff for: rosbag2_cpp/test/rosbag2_cpp/test_sequential_writer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ TEST_F(SequentialWriterTest, sequantial_writer_call_metadata_update_on_bag_split
226226
EXPECT_TRUE(v_intercepted_update_metadata_[0].compression_mode.empty());
227227
EXPECT_EQ(v_intercepted_update_metadata_[0].message_count, 0u); // On opening first bag file
228228
EXPECT_EQ(v_intercepted_update_metadata_[1].files.size(), 1u); // On closing first bag file
229-
EXPECT_EQ(v_intercepted_update_metadata_[2].files.size(), 1u); // On opening second bag file
229+
EXPECT_EQ(v_intercepted_update_metadata_[2].files.size(), 2u); // On opening second bag file
230230
EXPECT_EQ(v_intercepted_update_metadata_[3].files.size(), 2u); // On writer destruction
231231
EXPECT_EQ(v_intercepted_update_metadata_[3].message_count, 2 * kNumMessagesToWrite);
232232
}

0 commit comments

Comments
 (0)