Skip to content
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

Replaced tinydir with rcutils #605

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ find_package(rcutils REQUIRED)
find_package(rmw REQUIRED)
find_package(rmw_implementation REQUIRED)
find_package(rosidl_generator_c REQUIRED)
find_package(tinydir_vendor REQUIRED)
find_package(tracetools REQUIRED)

include_directories(include)
Expand Down Expand Up @@ -72,7 +71,6 @@ ament_target_dependencies(${PROJECT_NAME}
"rcutils"
"rosidl_generator_c"
${RCL_LOGGING_IMPL}
"tinydir_vendor"
"tracetools"
)

Expand Down
1 change: 0 additions & 1 deletion rcl/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<depend>rcutils</depend>
<depend>rmw_implementation</depend>
<depend>rosidl_generator_c</depend>
<depend>tinydir_vendor</depend>
<depend>tracetools</depend>

<test_depend>ament_cmake_gtest</test_depend>
Expand Down
36 changes: 18 additions & 18 deletions rcl/src/rcl/security_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@
#include "rcl/security_directory.h"

#include "rcl/error_handling.h"
#include "rcutils/directory_and_file_reader.h"
#include "rcutils/filesystem.h"
#include "rcutils/get_env.h"
#include "rcutils/format_string.h"

#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wembedded-directive"
#endif
#include "tinydir/tinydir.h"
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
#ifdef __clang__
# pragma clang diagnostic pop
#endif

/**
* A security lookup function takes in the node's name, namespace, a security root directory and an allocator;
* It returns the relevant information required to load the security credentials,
Expand Down Expand Up @@ -81,29 +73,29 @@ char * g_security_lookup_type_strings[] = {
* \param[in] base_dir
* \param[in] node_name
* \param[out] matched_name must be a valid memory address allocated with at least
* _TINYDIR_FILENAME_MAX characters.
* RCUTILS_FILENAME_MAX characters.
* \return true if a match was found
*/
static bool get_best_matching_directory(
const char * base_dir,
const char * node_name,
char * matched_name)
{
rcutils_dir_t dir = rcutils_get_zero_initialized_dir();
size_t max_match_length = 0;
tinydir_dir dir;
if (NULL == base_dir || NULL == node_name || NULL == matched_name) {
return false;
}
if (-1 == tinydir_open(&dir, base_dir)) {
if (-1 == rcutils_open_dir(&dir, base_dir, rcutils_get_default_allocator())) {
return false;
}
while (dir.has_next) {
tinydir_file file;
if (-1 == tinydir_readfile(&dir, &file)) {
rcutils_file_t file = rcutils_get_zero_initialized_file();
if (RCUTILS_RET_OK != rcutils_readfile(&dir, &file)) {
goto cleanup;
}
if (file.is_dir) {
size_t matched_name_length = strnlen(file.name, sizeof(file.name) - 1);
size_t matched_name_length = strlen(file.name);
if (
0 == strncmp(file.name, node_name, matched_name_length) &&
matched_name_length > max_match_length)
Expand All @@ -112,12 +104,20 @@ static bool get_best_matching_directory(
memcpy(matched_name, file.name, max_match_length);
}
}
if (-1 == tinydir_next(&dir)) {
rcutils_ret_t ret = rcutils_file_fini(&file, dir.allocator);
if (ret != RCUTILS_RET_OK) {
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING("%s", rcutils_get_error_string().str);
goto cleanup;
}
if (RCUTILS_RET_OK != rcutils_next_dir(&dir)) {
goto cleanup;
}
}

cleanup:
tinydir_close(&dir);
if (rcutils_close_dir(&dir) != RCUTILS_RET_OK) {
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING("%s", rcutils_get_error_string().str);
}
return max_match_length > 0;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ char * prefix_match_lookup(
{
// Perform longest prefix match for the node's name in directory <root dir>/<namespace>.
char * node_secure_root = NULL;
char matched_dir[_TINYDIR_FILENAME_MAX] = {0};
char matched_dir[RCUTILS_FILENAME_MAX] = {0};
char * base_lookup_dir = NULL;
if (strlen(node_namespace) == 1) {
base_lookup_dir = (char *) ros_secure_root_env;
Expand Down