From f0af89ad6fee292d7919e1681b0cb5bea9f30b8c Mon Sep 17 00:00:00 2001 From: Eden Zhang Date: Tue, 7 Jan 2025 17:20:38 +0000 Subject: [PATCH] Remove get_unambiguous_path function --- components/core/src/clp/Utils.cpp | 36 ---------------------------- components/core/src/clp/Utils.hpp | 7 ------ components/core/src/glt/Utils.cpp | 36 ---------------------------- components/core/src/glt/Utils.hpp | 7 ------ components/core/tests/test-Utils.cpp | 25 +------------------ 5 files changed, 1 insertion(+), 110 deletions(-) diff --git a/components/core/src/clp/Utils.cpp b/components/core/src/clp/Utils.cpp index 44c343cea..1c0fc05ca 100644 --- a/components/core/src/clp/Utils.cpp +++ b/components/core/src/clp/Utils.cpp @@ -88,42 +88,6 @@ ErrorCode create_directory_structure(string const& path, mode_t mode) { return ErrorCode_Success; } -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 7a9ffd33a..3238e551b 100644 --- a/components/core/src/clp/Utils.hpp +++ b/components/core/src/clp/Utils.hpp @@ -35,13 +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); -/** - * 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/src/glt/Utils.cpp b/components/core/src/glt/Utils.cpp index d39291339..0434372fe 100644 --- a/components/core/src/glt/Utils.cpp +++ b/components/core/src/glt/Utils.cpp @@ -84,42 +84,6 @@ ErrorCode create_directory_structure(string const& path, mode_t mode) { return ErrorCode_Success; } -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) { FileReader file_reader; ErrorCode error_code = file_reader.try_open(list_path); diff --git a/components/core/src/glt/Utils.hpp b/components/core/src/glt/Utils.hpp index 851a1ea72..302a13c73 100644 --- a/components/core/src/glt/Utils.hpp +++ b/components/core/src/glt/Utils.hpp @@ -33,13 +33,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); -/** - * 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 c12039e3f..fcc6bf262 100644 --- a/components/core/tests/test-Utils.cpp +++ b/components/core/tests/test-Utils.cpp @@ -14,7 +14,6 @@ using clp::create_directory_structure; using clp::ErrorCode_Success; -using clp::get_unambiguous_path; using std::string; TEST_CASE("create_directory_structure", "[create_directory_structure]") { @@ -42,26 +41,4 @@ TEST_CASE("create_directory_structure", "[create_directory_structure]") { REQUIRE(0 == rmdir("d")); REQUIRE(0 == rmdir("/tmp/5807")); -} - -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"); -} +} \ No newline at end of file