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

Recursively Search for .msg files #77

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions rosbag2_storage_mcap/src/message_definition_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string>
#include <unordered_set>
#include <utility>
#include <filesystem>

namespace rosbag2_storage_mcap::internal {

Expand Down Expand Up @@ -133,12 +134,22 @@ const MessageSpec& MessageDefinitionCache::load_message_spec(
}
std::string package = match[1];
std::string share_dir = ament_index_cpp::get_package_share_directory(package);
std::ifstream file{share_dir + "/msg/" + match[2].str() +
extension_for_format(definition_identifier.format)};
if (!file.good()) {
std::string target_file_name = match[2].str() + extension_for_format(definition_identifier.format);
std::string target_file_path;
// Recursively search install path for required file
// Depending on user setup, all .msg files could be present in <package_name>/msg/*.msg or <package_name>/<custom_name>/*.msg
for (auto& file : std::filesystem::recursive_directory_iterator(share_dir)) {
std::string found_file_name = file.path().filename();
if (found_file_name == target_file_name) {
target_file_path = file.path().string();
break;
}
}
if (target_file_path.empty()) {
throw DefinitionNotFoundError(definition_identifier.package_resource_name);
}

std::ifstream file{target_file_path};
std::string contents{std::istreambuf_iterator(file), {}};
const MessageSpec& spec =
msg_specs_by_definition_identifier_
Expand Down