From 232420621a5ea7ff64c98f3b4055e4d7b4ba714a Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sun, 4 Aug 2024 13:12:16 -0500 Subject: [PATCH] updated build system --- support/include/utils/path.hpp | 2 +- support/src/utils/path.cpp | 17 +++++++++++------ support/test/src/utils/path_test.cpp | 9 ++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/support/include/utils/path.hpp b/support/include/utils/path.hpp index ad8f57d6..897cb8ef 100644 --- a/support/include/utils/path.hpp +++ b/support/include/utils/path.hpp @@ -370,7 +370,7 @@ format_path(string_t &path, #if defined(_WIN32) if ((path.size() >= 2U) && (path.at(1U) == ':')) { - path[0U] = utils::string::to_lower(string_t{1U, path.at(0U)}).at(0U); + path[0U] = utils::string::to_lower(string_t(1U, path.at(0U))).at(0U); } #endif // defined(_WIN32) diff --git a/support/src/utils/path.cpp b/support/src/utils/path.cpp index cf88dea2..6f44591f 100644 --- a/support/src/utils/path.cpp +++ b/support/src/utils/path.cpp @@ -41,8 +41,11 @@ static const std::wstring directory_seperator_str_w{ repertory::utils::string::contains(path, "%")) { repertory::utils::string::replace(path, "~", "%USERPROFILE%"); + auto size = ::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0); + std::cout << size << std::endl; + std::string dest; - dest.resize(::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0)); + dest.resize(size); ::ExpandEnvironmentStringsA(path.c_str(), dest.data(), static_cast(dest.size())); path = dest.c_str(); @@ -68,6 +71,9 @@ static const std::wstring directory_seperator_str_w{ namespace repertory::utils::path { auto absolute(std::string_view path) -> std::string { std::string abs_path{path}; + abs_path = resolve(abs_path); + format_path(abs_path, directory_seperator, not_directory_seperator); + #if defined(_WIN32) if (not abs_path.empty() && ::PathIsRelativeA(abs_path.c_str())) { std::string temp; @@ -75,14 +81,14 @@ auto absolute(std::string_view path) -> std::string { abs_path = _fullpath(temp.data(), abs_path.c_str(), MAX_PATH); } #else // !defined(_WIN32) - abs_path = resolve(finalize(abs_path)); if (not abs_path.empty() && (abs_path.at(0U) != '/')) { auto found{false}; std::string tmp{abs_path}; do { auto *res = realpath(tmp.c_str(), nullptr); - if (res) { - abs_path = combine(res, {abs_path.substr(tmp.size())}); + if (res != nullptr) { + abs_path = res + std::string{directory_seperator} + + abs_path.substr(tmp.size()); free(res); found = true; } else if (tmp == ".") { @@ -94,8 +100,7 @@ auto absolute(std::string_view path) -> std::string { } #endif // defined(_WIN32) - return format_path(abs_path, get_directory_seperator(), - get_not_directory_seperator()); + return format_path(abs_path, directory_seperator, not_directory_seperator); } auto absolute(std::wstring_view path) -> std::wstring { diff --git a/support/test/src/utils/path_test.cpp b/support/test/src/utils/path_test.cpp index 27f9bce5..e14b5dcd 100644 --- a/support/test/src/utils/path_test.cpp +++ b/support/test/src/utils/path_test.cpp @@ -255,7 +255,14 @@ TEST(utils_path, absolute) { path = utils::path::absolute("./"); EXPECT_STREQ(dir.c_str(), path.c_str()); - auto home = utils::path::absolute(utils::get_environment_variable("HOME")); +#if defined(_WIN32) + auto home_env = utils::get_environment_variable("USERPROFILE"); +#else // !defined(_WIN32) + auto home_env = utils::get_environment_variable("HOME"); +#endif // defined(_WIN32) + + auto home = utils::path::absolute(home_env); + path = utils::path::absolute("~"); EXPECT_STREQ(home.c_str(), path.c_str());