Skip to content

Commit

Permalink
Revert "Refactor paths to use rcpputils filesystem helper (#46)"
Browse files Browse the repository at this point in the history
This reverts commit 5954265.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
  • Loading branch information
clalancette committed Feb 21, 2020
1 parent 126dcdb commit 1240d39
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 31 deletions.
2 changes: 0 additions & 2 deletions ament_index_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ unless the library was explicitly added as a static library."
ON)

find_package(ament_cmake REQUIRED)
find_package(rcpputils REQUIRED)

add_library(${PROJECT_NAME}
src/get_package_prefix.cpp
Expand All @@ -33,7 +32,6 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE "AMENT_INDEX_CPP_BUILDING_DLL
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
ament_target_dependencies(${PROJECT_NAME} rcpputils)

ament_export_include_directories(include)
ament_export_interfaces(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
Expand Down
2 changes: 0 additions & 2 deletions ament_index_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>rcpputils</depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
6 changes: 1 addition & 5 deletions ament_index_cpp/src/get_package_share_directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include <string>

#include "rcpputils/filesystem_helper.hpp"

#include "ament_index_cpp/get_package_prefix.hpp"

namespace ament_index_cpp
Expand All @@ -26,9 +24,7 @@ namespace ament_index_cpp
std::string
get_package_share_directory(const std::string & package_name)
{
auto share_directory =
rcpputils::fs::path{get_package_prefix(package_name)} / "share" / package_name;
return share_directory.string();
return get_package_prefix(package_name) + "/share/" + package_name;
}

} // namespace ament_index_cpp
8 changes: 3 additions & 5 deletions ament_index_cpp/src/get_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <stdexcept>
#include <string>

#include "rcpputils/filesystem_helper.hpp"

#include "ament_index_cpp/get_search_paths.hpp"

namespace ament_index_cpp
Expand All @@ -41,9 +39,9 @@ get_resource(
}
auto paths = get_search_paths();
for (auto path : paths) {
auto resource_path = rcpputils::fs::path{path} / "share" / "ament_index" / "resource_index" /
resource_type / resource_name;
std::ifstream s(resource_path.string());
auto resource_path = path + "/share/ament_index/resource_index/" +
resource_type + "/" + resource_name;
std::ifstream s(resource_path);
if (s.is_open()) {
std::stringstream buffer;
buffer << s.rdbuf();
Expand Down
11 changes: 4 additions & 7 deletions ament_index_cpp/src/get_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <stdexcept>
#include <string>

#include "rcpputils/filesystem_helper.hpp"

#include "ament_index_cpp/get_search_paths.hpp"

namespace ament_index_cpp
Expand All @@ -40,18 +38,17 @@ get_resources(const std::string & resource_type)
std::map<std::string, std::string> resources;
auto paths = get_search_paths();
for (auto base_path : paths) {
auto path =
rcpputils::fs::path{base_path} / "share" / "ament_index" / "resource_index" / resource_type;
auto path = base_path + "/share/ament_index/resource_index/" + resource_type;

#ifndef _WIN32
auto dir = opendir(path.string().c_str());
auto dir = opendir(path.c_str());
if (!dir) {
continue;
}
dirent * entry;
while ((entry = readdir(dir)) != NULL) {
// ignore directories
auto subdir = opendir((path / entry->d_name).string().c_str());
auto subdir = opendir((path + "/" + entry->d_name).c_str());
if (subdir) {
closedir(subdir);
continue;
Expand All @@ -72,7 +69,7 @@ get_resources(const std::string & resource_type)
closedir(dir);

#else
const auto pattern = (path / "*").string();
std::string pattern = path + "/*";
WIN32_FIND_DATA find_data;
HANDLE find_handle = FindFirstFile(pattern.c_str(), &find_data);
if (find_handle == INVALID_HANDLE_VALUE) {
Expand Down
8 changes: 3 additions & 5 deletions ament_index_cpp/src/has_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <stdexcept>
#include <string>

#include "rcpputils/filesystem_helper.hpp"

#include "ament_index_cpp/get_search_paths.hpp"

namespace ament_index_cpp
Expand All @@ -39,9 +37,9 @@ has_resource(
}
auto paths = get_search_paths();
for (auto path : paths) {
auto resource_path = rcpputils::fs::path{path} / "share" / "ament_index" / "resource_index" /
resource_type / resource_name;
std::ifstream s(resource_path.string());
auto resource_path = path + "/share/ament_index/resource_index/" +
resource_type + "/" + resource_name;
std::ifstream s(resource_path);
if (s.is_open()) {
if (prefix_path) {
*prefix_path = path;
Expand Down
6 changes: 1 addition & 5 deletions ament_index_cpp/test/utest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <stdexcept>
#include <string>

#include "rcpputils/filesystem_helper.hpp"

#include "ament_index_cpp/get_package_prefix.hpp"
#include "ament_index_cpp/get_package_share_directory.hpp"
#include "ament_index_cpp/get_packages_with_prefixes.hpp"
Expand Down Expand Up @@ -255,10 +253,8 @@ TEST(AmentIndexCpp, get_package_share_directory) {
subfolders.push_back("prefix2"); // only contains bar and baz packages
set_ament_prefix_path(subfolders);
// bar is in both, but prefix 1 takes precedence
const auto subfolder_path =
rcpputils::fs::path{generate_subfolder_path("prefix1")} / "share" / "bar";
EXPECT_EQ(
subfolder_path.string(),
generate_subfolder_path("prefix1") + "/share/bar",
ament_index_cpp::get_package_share_directory("bar"));
}

Expand Down

0 comments on commit 1240d39

Please sign in to comment.