diff --git a/components/core/src/clp/Utils.cpp b/components/core/src/clp/Utils.cpp index f487a3880..1c0fc05ca 100644 --- a/components/core/src/clp/Utils.cpp +++ b/components/core/src/clp/Utils.cpp @@ -88,57 +88,6 @@ ErrorCode create_directory_structure(string const& path, mode_t mode) { return ErrorCode_Success; } -string get_parent_directory_path(string const& path) { - string dirname = get_unambiguous_path(path); - - size_t last_slash_pos = dirname.find_last_of('/'); - if (0 == last_slash_pos) { - dirname = "/"; - } else if (string::npos == last_slash_pos) { - dirname = "."; - } else { - dirname.resize(last_slash_pos); - } - - return dirname; -} - -string get_unambiguous_path(string const& path) { - string unambiguous_path; - if (path.empty()) { - return unambiguous_path; - } - - // Break path into components - vector path_components; - boost::split(path_components, path, boost::is_any_of("/"), boost::token_compress_on); - - // Remove ambiguous components - list unambiguous_components; - size_t num_components_to_ignore = 0; - for (size_t i = path_components.size(); i-- > 0;) { - if (".." == path_components[i]) { - ++num_components_to_ignore; - } else if ("." == path_components[i] || path_components[i].empty()) { - // Do nothing - } else if (num_components_to_ignore > 0) { - --num_components_to_ignore; - } else { - unambiguous_components.emplace_front(path_components[i]); - } - } - - // Assemble unambiguous path from leading slash (if any) and the unambiguous components - if ('/' == path[0]) { - unambiguous_path += '/'; - } - if (!unambiguous_components.empty()) { - unambiguous_path += boost::join(unambiguous_components, "/"); - } - - return unambiguous_path; -} - ErrorCode read_list_of_paths(string const& list_path, vector& paths) { unique_ptr file_reader; try { diff --git a/components/core/src/clp/Utils.hpp b/components/core/src/clp/Utils.hpp index de7f81aae..3238e551b 100644 --- a/components/core/src/clp/Utils.hpp +++ b/components/core/src/clp/Utils.hpp @@ -35,28 +35,6 @@ ErrorCode create_directory(std::string const& path, mode_t mode, bool exist_ok); */ ErrorCode create_directory_structure(std::string const& path, mode_t mode); -/** - * Gets the parent directory path for a given path - * Corner cases: - * - get_dirname("abc") = "." - * - get_dirname(".") = "." - * - get_dirname("..") = "." - * - get_dirname("/") = "/" - * - get_dirname("/.") = "/" - * - get_dirname("/..") = "/" - * - get_dirname("/abc") = "/" - * @param path - * @return Parent directory path - */ -std::string get_parent_directory_path(std::string const& path); - -/** - * Removes ".", "..", and consecutive "/" from a given path and returns the result - * @param path The given path - * @return The unambiguous path - */ -std::string get_unambiguous_path(std::string const& path); - /** * Read a list of paths from a file * @param list_path diff --git a/components/core/tests/test-Utils.cpp b/components/core/tests/test-Utils.cpp index 603fb4be0..21d070f92 100644 --- a/components/core/tests/test-Utils.cpp +++ b/components/core/tests/test-Utils.cpp @@ -14,8 +14,6 @@ using clp::create_directory_structure; using clp::ErrorCode_Success; -using clp::get_parent_directory_path; -using clp::get_unambiguous_path; using std::string; TEST_CASE("create_directory_structure", "[create_directory_structure]") { @@ -44,41 +42,3 @@ TEST_CASE("create_directory_structure", "[create_directory_structure]") { REQUIRE(0 == rmdir("/tmp/5807")); } - -TEST_CASE("get_parent_directory_path", "[get_parent_directory_path]") { - // Corner cases - // Anything without a slash should return "." - REQUIRE(get_parent_directory_path(".") == "."); - REQUIRE(get_parent_directory_path("..") == "."); - REQUIRE(get_parent_directory_path("abc") == "."); - // A single slash, at the beginning, should always return "/" - REQUIRE(get_parent_directory_path("/") == "/"); - REQUIRE(get_parent_directory_path("/.") == "/"); - REQUIRE(get_parent_directory_path("/..") == "/"); - REQUIRE(get_parent_directory_path("/abc") == "/"); - - // Normal cases - REQUIRE(get_parent_directory_path("//abc/./def//../def/.///") == "/abc"); -} - -TEST_CASE("get_unambiguous_path", "[get_unambiguous_path]") { - // Base cases (should not modify anything) - REQUIRE(get_unambiguous_path("/") == "/"); - REQUIRE(get_unambiguous_path("abc") == "abc"); - REQUIRE(get_unambiguous_path("/abc") == "/abc"); - REQUIRE(get_unambiguous_path("/abc/def") == "/abc/def"); - - // Corner cases - REQUIRE(get_unambiguous_path(".").empty()); - REQUIRE(get_unambiguous_path("..").empty()); - REQUIRE(get_unambiguous_path("////") == "/"); - REQUIRE(get_unambiguous_path("/./.././//../") == "/"); - REQUIRE(get_unambiguous_path("./.././//../").empty()); - REQUIRE(get_unambiguous_path("/abc/def/.././../") == "/"); - REQUIRE(get_unambiguous_path("abc/def/.././../").empty()); - - // Normal cases - REQUIRE(get_unambiguous_path("/abc///def/../ghi/./") == "/abc/ghi"); - REQUIRE(get_unambiguous_path("abc///def/../ghi/./") == "abc/ghi"); - REQUIRE(get_unambiguous_path("../abc///def/../ghi/./") == "abc/ghi"); -}