-
Notifications
You must be signed in to change notification settings - Fork 294
Update rosbag2 filename format to index+name+timestamp #2265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rolling
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |||||||||||||
| #include <filesystem> | ||||||||||||||
| #include <fstream> | ||||||||||||||
| #include <memory> | ||||||||||||||
| #include <regex> | ||||||||||||||
| #include <sstream> | ||||||||||||||
| #include <string> | ||||||||||||||
| #include <utility> | ||||||||||||||
| #include <vector> | ||||||||||||||
|
|
@@ -27,6 +29,7 @@ | |||||||||||||
| #include "rosbag2_compression/sequential_compression_writer.hpp" | ||||||||||||||
|
|
||||||||||||||
| #include "rosbag2_cpp/writer.hpp" | ||||||||||||||
| #include "rosbag2_cpp/writers/sequential_writer.hpp" | ||||||||||||||
|
|
||||||||||||||
| #include "rosbag2_storage/ros_helper.hpp" | ||||||||||||||
| #include "rosbag2_storage/storage_options.hpp" | ||||||||||||||
|
|
@@ -304,12 +307,29 @@ TEST_F(SequentialCompressionWriterTest, writer_creates_correct_metadata_relative | |||||||||||||
|
|
||||||||||||||
| EXPECT_EQ(intercepted_write_metadata_.relative_file_paths.size(), 3u); | ||||||||||||||
|
|
||||||||||||||
| // New filename format: {counter}_{bag_base_dir}_{timestamp}.{compressor} | ||||||||||||||
| // Timestamp is generated at runtime, so validate using regex | ||||||||||||||
| // Use static to avoid recompiling regex on each test run | ||||||||||||||
| static const std::string file_pattern_str = | ||||||||||||||
| R"(\d+_)" + std::string("test_bag") + R"(_)" + | ||||||||||||||
| std::string(rosbag2_cpp::writers::TIMESTAMP_PATTERN) + | ||||||||||||||
| R"(\.)" + std::string(DefaultTestCompressor); | ||||||||||||||
| static const std::regex file_pattern(file_pattern_str); | ||||||||||||||
|
|
||||||||||||||
| int counter = 0; | ||||||||||||||
| for (const auto & path : intercepted_write_metadata_.relative_file_paths) { | ||||||||||||||
| std::stringstream ss; | ||||||||||||||
| ss << bag_base_dir_ << "_" << counter << "." << DefaultTestCompressor; | ||||||||||||||
| // Verify that filename matches expected format | ||||||||||||||
| EXPECT_TRUE(std::regex_match(path, file_pattern)) << | ||||||||||||||
| "Path '" << path << "' does not match expected pattern for file " << counter; | ||||||||||||||
|
|
||||||||||||||
| // Verify that counter is at the correct position | ||||||||||||||
| std::stringstream expected_prefix; | ||||||||||||||
| expected_prefix << counter << "_" << bag_base_dir_ << "_"; | ||||||||||||||
| EXPECT_TRUE(path.find(expected_prefix.str()) == 0) << | ||||||||||||||
| "Path '" << path << "' does not start with expected prefix '" << | ||||||||||||||
| expected_prefix.str() << "'"; | ||||||||||||||
|
|
||||||||||||||
| counter++; | ||||||||||||||
| EXPECT_EQ(ss.str(), path); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -546,14 +566,44 @@ TEST_P(SequentialCompressionWriterTest, split_event_calls_callback_with_msg_comp | |||||||||||||
|
|
||||||||||||||
| ASSERT_GE(opened_files.size(), num_splits + 1); | ||||||||||||||
| ASSERT_GE(closed_files.size(), num_splits + 1); | ||||||||||||||
|
|
||||||||||||||
| // New filename format: {counter}_{bag_base_dir}_{timestamp} | ||||||||||||||
| // Timestamp is generated at runtime, so validate using regex | ||||||||||||||
| static const std::string file_pattern_str = | ||||||||||||||
| R"(\d+_)" + std::string("test_bag") + R"(_)" + | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| std::string(rosbag2_cpp::writers::TIMESTAMP_PATTERN); | ||||||||||||||
| static const std::regex file_pattern(file_pattern_str); | ||||||||||||||
|
|
||||||||||||||
| for (size_t i = 0; i < num_splits + 1; i++) { | ||||||||||||||
| auto expected_closed = | ||||||||||||||
| fs::path(tmp_dir_storage_options_.uri) / (bag_base_dir_ + "_" + std::to_string(i)); | ||||||||||||||
| auto expected_opened = (i == num_splits) ? | ||||||||||||||
| // Verify closed file format | ||||||||||||||
| fs::path closed_path(closed_files[i]); | ||||||||||||||
| std::string closed_filename = closed_path.filename().generic_string(); | ||||||||||||||
| EXPECT_TRUE(std::regex_match(closed_filename, file_pattern)) << | ||||||||||||||
| "Closed file '" << closed_filename << "' does not match expected pattern for file " << i; | ||||||||||||||
|
|
||||||||||||||
| // Verify counter is at the correct position | ||||||||||||||
| std::stringstream expected_prefix; | ||||||||||||||
| expected_prefix << i << "_" << bag_base_dir_ << "_"; | ||||||||||||||
| EXPECT_TRUE(closed_filename.find(expected_prefix.str()) == 0) << | ||||||||||||||
| "Closed file '" << closed_filename << "' does not start with expected prefix '" << | ||||||||||||||
| expected_prefix.str() << "'"; | ||||||||||||||
|
Comment on lines
+585
to
+589
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| // Verify opened file format | ||||||||||||||
| if (i == num_splits) { | ||||||||||||||
| // The last opened file shall be empty string when we do "writer->close();" | ||||||||||||||
| "" : fs::path(tmp_dir_storage_options_.uri) / (bag_base_dir_ + "_" + std::to_string(i + 1)); | ||||||||||||||
| EXPECT_EQ(closed_files[i], expected_closed.generic_string()) << "i = " << i; | ||||||||||||||
| EXPECT_EQ(opened_files[i], expected_opened.generic_string()) << "i = " << i; | ||||||||||||||
| EXPECT_EQ(opened_files[i], "") << "i = " << i; | ||||||||||||||
| } else { | ||||||||||||||
| fs::path opened_path(opened_files[i]); | ||||||||||||||
| std::string opened_filename = opened_path.filename().generic_string(); | ||||||||||||||
| EXPECT_TRUE(std::regex_match(opened_filename, file_pattern)) << | ||||||||||||||
| "Opened file '" << opened_filename << "' does not match expected pattern for file " << i; | ||||||||||||||
|
|
||||||||||||||
| std::stringstream expected_opened_prefix; | ||||||||||||||
| expected_opened_prefix << (i + 1) << "_" << bag_base_dir_ << "_"; | ||||||||||||||
| EXPECT_TRUE(opened_filename.find(expected_opened_prefix.str()) == 0) << | ||||||||||||||
| "Opened file '" << opened_filename << "' does not start with expected prefix '" << | ||||||||||||||
| expected_opened_prefix.str() << "'"; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -616,15 +666,49 @@ TEST_P(SequentialCompressionWriterTest, split_event_calls_callback_with_file_com | |||||||||||||
|
|
||||||||||||||
| ASSERT_GE(opened_files.size(), num_splits + 1); | ||||||||||||||
| ASSERT_GE(closed_files.size(), num_splits + 1); | ||||||||||||||
|
|
||||||||||||||
| // New filename format: {counter}_{bag_base_dir}_{timestamp}.{compressor} | ||||||||||||||
| // Timestamp is generated at runtime, so validate using regex | ||||||||||||||
| static const std::string closed_file_pattern_str = | ||||||||||||||
| R"(\d+_)" + std::string("test_bag") + R"(_)" + | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| std::string(rosbag2_cpp::writers::TIMESTAMP_PATTERN) + | ||||||||||||||
| R"(\.)" + std::string(DefaultTestCompressor); | ||||||||||||||
| static const std::regex closed_file_pattern(closed_file_pattern_str); | ||||||||||||||
| static const std::string opened_file_pattern_str = | ||||||||||||||
| R"(\d+_)" + std::string("test_bag") + R"(_)" + | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| std::string(rosbag2_cpp::writers::TIMESTAMP_PATTERN); | ||||||||||||||
| static const std::regex opened_file_pattern(opened_file_pattern_str); | ||||||||||||||
|
|
||||||||||||||
| for (size_t i = 0; i < num_splits + 1; i++) { | ||||||||||||||
| auto expected_closed = | ||||||||||||||
| fs::path(tmp_dir_storage_options_.uri) / (bag_base_dir_ + "_" + std::to_string(i) + | ||||||||||||||
| "." + DefaultTestCompressor); | ||||||||||||||
| auto expected_opened = (i == num_splits) ? | ||||||||||||||
| // Verify closed file format | ||||||||||||||
| fs::path closed_path(closed_files[i]); | ||||||||||||||
| std::string closed_filename = closed_path.filename().generic_string(); | ||||||||||||||
| EXPECT_TRUE(std::regex_match(closed_filename, closed_file_pattern)) << | ||||||||||||||
| "Closed file '" << closed_filename << "' does not match expected pattern for file " << i; | ||||||||||||||
|
|
||||||||||||||
| // Verify counter is at the correct position | ||||||||||||||
| std::stringstream expected_prefix; | ||||||||||||||
| expected_prefix << i << "_" << bag_base_dir_ << "_"; | ||||||||||||||
| EXPECT_TRUE(closed_filename.find(expected_prefix.str()) == 0) << | ||||||||||||||
| "Closed file '" << closed_filename << "' does not start with expected prefix '" << | ||||||||||||||
| expected_prefix.str() << "'"; | ||||||||||||||
|
|
||||||||||||||
| // Verify opened file format | ||||||||||||||
| if (i == num_splits) { | ||||||||||||||
| // The last opened file shall be empty string when we do "writer->close();" | ||||||||||||||
| "" : fs::path(tmp_dir_storage_options_.uri) / (bag_base_dir_ + "_" + std::to_string(i + 1)); | ||||||||||||||
| EXPECT_EQ(closed_files[i], expected_closed.generic_string()) << "i = " << i; | ||||||||||||||
| EXPECT_EQ(opened_files[i], expected_opened.generic_string()) << "i = " << i; | ||||||||||||||
| EXPECT_EQ(opened_files[i], "") << "i = " << i; | ||||||||||||||
| } else { | ||||||||||||||
| fs::path opened_path(opened_files[i]); | ||||||||||||||
| std::string opened_filename = opened_path.filename().generic_string(); | ||||||||||||||
| EXPECT_TRUE(std::regex_match(opened_filename, opened_file_pattern)) << | ||||||||||||||
| "Opened file '" << opened_filename << "' does not match expected pattern for file " << i; | ||||||||||||||
|
|
||||||||||||||
| std::stringstream expected_opened_prefix; | ||||||||||||||
| expected_opened_prefix << (i + 1) << "_" << bag_base_dir_ << "_"; | ||||||||||||||
| EXPECT_TRUE(opened_filename.find(expected_opened_prefix.str()) == 0) << | ||||||||||||||
| "Opened file '" << opened_filename << "' does not start with expected prefix '" << | ||||||||||||||
| expected_opened_prefix.str() << "'"; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -690,15 +774,48 @@ TEST_F(SequentialCompressionWriterTest, snapshot_writes_to_new_file_with_file_co | |||||||||||||
| ASSERT_EQ(opened_files.size(), 2); | ||||||||||||||
| ASSERT_EQ(closed_files.size(), 2); | ||||||||||||||
|
|
||||||||||||||
| // New filename format: {counter}_{bag_base_dir}_{timestamp}.{compressor} | ||||||||||||||
| // Timestamp is generated at runtime, so validate using regex | ||||||||||||||
| static const std::string closed_file_pattern_str = | ||||||||||||||
| R"(\d+_)" + std::string("test_bag") + R"(_)" + | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| std::string(rosbag2_cpp::writers::TIMESTAMP_PATTERN) + | ||||||||||||||
| R"(\.)" + std::string(DefaultTestCompressor); | ||||||||||||||
| static const std::regex closed_file_pattern(closed_file_pattern_str); | ||||||||||||||
| static const std::string opened_file_pattern_str = | ||||||||||||||
| R"(\d+_)" + std::string("test_bag") + R"(_)" + | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| std::string(rosbag2_cpp::writers::TIMESTAMP_PATTERN); | ||||||||||||||
| static const std::regex opened_file_pattern(opened_file_pattern_str); | ||||||||||||||
|
|
||||||||||||||
| for (size_t i = 0; i < 2; i++) { | ||||||||||||||
| auto expected_closed = fs::path(tmp_dir_storage_options_.uri) / | ||||||||||||||
| (bag_base_dir_ + "_" + std::to_string(i) + "." + DefaultTestCompressor); | ||||||||||||||
| auto expected_opened = (i == 1) ? | ||||||||||||||
| // Verify closed file format | ||||||||||||||
| fs::path closed_path(closed_files[i]); | ||||||||||||||
| std::string closed_filename = closed_path.filename().generic_string(); | ||||||||||||||
| EXPECT_TRUE(std::regex_match(closed_filename, closed_file_pattern)) << | ||||||||||||||
| "Closed file '" << closed_filename << "' does not match expected pattern for file " << i; | ||||||||||||||
|
|
||||||||||||||
| // Verify counter is at the correct position | ||||||||||||||
| std::stringstream expected_prefix; | ||||||||||||||
| expected_prefix << i << "_" << bag_base_dir_ << "_"; | ||||||||||||||
| EXPECT_TRUE(closed_filename.find(expected_prefix.str()) == 0) << | ||||||||||||||
| "Closed file '" << closed_filename << "' does not start with expected prefix '" << | ||||||||||||||
| expected_prefix.str() << "'"; | ||||||||||||||
|
|
||||||||||||||
| // Verify opened file format | ||||||||||||||
| if (i == 1) { | ||||||||||||||
| // The last opened file shall be empty string when we do "writer->close();" | ||||||||||||||
| "" : fs::path(tmp_dir_storage_options_.uri) / | ||||||||||||||
| (bag_base_dir_ + "_" + std::to_string(i + 1)); | ||||||||||||||
| ASSERT_STREQ(closed_files[i].c_str(), expected_closed.generic_string().c_str()); | ||||||||||||||
| ASSERT_STREQ(opened_files[i].c_str(), expected_opened.generic_string().c_str()); | ||||||||||||||
| EXPECT_EQ(opened_files[i], "") << "i = " << i; | ||||||||||||||
| } else { | ||||||||||||||
| fs::path opened_path(opened_files[i]); | ||||||||||||||
| std::string opened_filename = opened_path.filename().generic_string(); | ||||||||||||||
| EXPECT_TRUE(std::regex_match(opened_filename, opened_file_pattern)) << | ||||||||||||||
| "Opened file '" << opened_filename << "' does not match expected pattern for file " << i; | ||||||||||||||
|
|
||||||||||||||
| std::stringstream expected_opened_prefix; | ||||||||||||||
| expected_opened_prefix << (i + 1) << "_" << bag_base_dir_ << "_"; | ||||||||||||||
| EXPECT_TRUE(opened_filename.find(expected_opened_prefix.str()) == 0) << | ||||||||||||||
| "Opened file '" << opened_filename << "' does not start with expected prefix '" << | ||||||||||||||
| expected_opened_prefix.str() << "'"; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,7 +89,8 @@ class ROSBAG2_CPP_PUBLIC Reindexer | |
| std::vector<rosbag2_storage::TopicMetadata> topics_metadata_{}; | ||
|
|
||
| private: | ||
| std::string regex_bag_pattern_; | ||
| std::string new_format_regex_; | ||
| std::string old_format_regex_; | ||
|
Comment on lines
+92
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: Please rename to the const std::string new_file_format_regex_str_ =
R"((\d+)_(.*)_)" + std::string(rosbag2_cpp::writers::TIMESTAMP_PATTERN) +
R"(\.[a-zA-Z0-9]+){1,2})";
const std::string old_file_format_regex_str_ = R"((.*)_(\d+)(\.[a-zA-Z0-9]+){1,2})"; |
||
| std::filesystem::path base_folder_; // The folder that the bag files are in | ||
| std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory_{}; | ||
| void get_bag_files( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,8 +16,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <algorithm> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <chrono> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <ctime> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <filesystem> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <iomanip> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <memory> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <regex> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <stdexcept> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <sstream> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -295,9 +298,45 @@ std::string SequentialWriter::format_storage_uri( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Right now `base_folder_` is always just the folder name for where to install the bagfile. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The name of the folder needs to be queried in case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SequentialWriter is opened with a relative path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
295
to
297
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can delete the original comment it has become irrelevant and outdated
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Extract prefix from directory name by removing timestamp pattern if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This handles the case when --output is not specified and default timestamped directory is used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Currently, the default timestamp format is `YYYY_MM_DD-HH_MM_SS` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::string dir_name = fs::path(base_folder).filename().generic_string(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Handle edge case where filename() returns empty (e.g., base_folder is "/" or ".") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This should not happen in practice since base_folder is validated in open(), but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // we add this check for defensive programming. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (dir_name.empty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dir_name = "rosbag2"; // Use default prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static std::regex timestamp_pattern("_" + std::string(TIMESTAMP_PATTERN) + "$"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::string prefix = std::regex_replace(dir_name, timestamp_pattern, ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Generate timestamp at file creation time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Timestamp is generated in local time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // During DST switches the same string may occur twice. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The sequence counter is part of the filename, so duplicates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // still remain distinguishable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto now = std::chrono::system_clock::now(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto time_t = std::chrono::system_clock::to_time_t(now); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::tm tm_buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef _WIN32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| localtime_s(&tm_buf, &time_t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| localtime_r(&time_t, &tm_buf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::stringstream timestamp_stream; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timestamp_stream << std::put_time(&tm_buf, "%Y_%m_%d-%H_%M_%S"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::string timestamp = timestamp_stream.str(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Generate filename in format {storage_count}_{prefix}_{timestamp} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Note: Underscores are used as separators. If the prefix contains underscores, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // this creates theoretical ambiguity when parsing filenames. However, parsing is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // typically done by matching the timestamp pattern from the end, which avoids | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ambiguity in practice. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+301
to
+337
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: to shorten the body and rephrase a bit comments.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::stringstream storage_file_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| storage_file_name << fs::path(base_folder).filename().generic_string() << "_" << | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| storage_count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| storage_file_name << storage_count << "_" << prefix << "_" << timestamp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (fs::path(base_folder) / storage_file_name.str()).generic_string(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please declare the following helper functions as public methods of the
SequentialCompressionWriterTesttest fixture to check the path in multiple places, the same way, and avoid code duplication.Expected usage: