Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 93b1073

Browse files
committed
recursively search for msg files
Signed-off-by: aditya2592 <[email protected]>
1 parent 17c8db3 commit 93b1073

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

rosbag2_storage_mcap/src/message_definition_cache.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <string>
2828
#include <unordered_set>
2929
#include <utility>
30+
#include <filesystem>
3031

3132
namespace rosbag2_storage_mcap::internal {
3233

@@ -133,12 +134,22 @@ const MessageSpec& MessageDefinitionCache::load_message_spec(
133134
}
134135
std::string package = match[1];
135136
std::string share_dir = ament_index_cpp::get_package_share_directory(package);
136-
std::ifstream file{share_dir + "/msg/" + match[2].str() +
137-
extension_for_format(definition_identifier.format)};
138-
if (!file.good()) {
137+
std::string target_file_name = match[2].str() + extension_for_format(definition_identifier.format);
138+
std::string target_file_path;
139+
// Recursively search install path for required file
140+
// Depending on user setup, all .msg files could be present in <package_name>/msg/*.msg or <package_name>/<custom_name>/*.msg
141+
for (auto& file : std::filesystem::recursive_directory_iterator(share_dir)) {
142+
std::string found_file_name = file.path().filename();
143+
if (found_file_name == target_file_name) {
144+
target_file_path = file.path().string();
145+
break;
146+
}
147+
}
148+
if (target_file_path.empty()) {
139149
throw DefinitionNotFoundError(definition_identifier.package_resource_name);
140150
}
141151

152+
std::ifstream file{target_file_path};
142153
std::string contents{std::istreambuf_iterator(file), {}};
143154
const MessageSpec& spec =
144155
msg_specs_by_definition_identifier_

0 commit comments

Comments
 (0)