diff --git a/support/3rd_party/src/utils/common.cpp b/support/3rd_party/src/utils/common.cpp index 9b1e10d3..e7f298a1 100644 --- a/support/3rd_party/src/utils/common.cpp +++ b/support/3rd_party/src/utils/common.cpp @@ -21,6 +21,7 @@ */ #include "utils/common.hpp" +#include "utils/path.hpp" #include "utils/string.hpp" namespace repertory::utils { @@ -138,28 +139,7 @@ auto get_next_available_port(std::uint16_t first_port, #endif // defined(PROJECT_ENABLE_BOOST) auto resolve_variables(std::string str) -> std::string { -#if defined(HAS_WORDEXP_H) - wordexp_t wt{}; - int ret{}; - if ((ret = wordexp(std::string{str}.c_str(), &wt, 0)) != 0) { - throw std::runtime_error("'wordexp()' failed|" + std::to_string(ret)); - } - str = wt.we_wordv[0U]; - wordfree(&wt); -#else // !defined(HAS_WORDEXP_H) - std::string dest; - dest.resize(::ExpandEnvironmentStringsA(str.c_str(), nullptr, 0)); - ::ExpandEnvironmentStringsA(str.c_str(), dest.data(), - static_cast(dest.size())); - str = std::string(dest.c_str(), strlen(dest.c_str())); - - dest.resize(::GetFullPathNameA(str.c_str(), 0, nullptr, nullptr)); - ::GetFullPathNameA(str.c_str(), static_cast(dest.size()), dest.data(), - nullptr); - str = std::string(dest.c_str(), strlen(dest.c_str())); -#endif // defined(HAS_WORDEXP_H) - - return str; + return utils::path::absolute(str); } auto resolve_variables(std::wstring_view str) -> std::wstring { diff --git a/support/3rd_party/src/utils/path.cpp b/support/3rd_party/src/utils/path.cpp index 51ff88f9..f62a8a2d 100644 --- a/support/3rd_party/src/utils/path.cpp +++ b/support/3rd_party/src/utils/path.cpp @@ -36,23 +36,28 @@ static const std::wstring directory_seperator_str_w{ #if !defined(_WIN32) [[nodiscard]] auto resolve(std::string path) -> std::string { - std::string home{}; - repertory::utils::use_getpwuid(getuid(), [&home](struct passwd *pw) { - home = (pw->pw_dir ? pw->pw_dir : ""); - if (home.empty() || ((home == "/") && (getuid() != 0))) { - home = repertory::utils::path::combine("/home", {pw->pw_name}); - } - }); +#if defined(HAS_WORDEXP_H) + wordexp_t wt{}; + int ret{}; + if ((ret = wordexp(path.c_str(), &wt, 0)) != 0) { + throw std::runtime_error("'wordexp()' failed|" + std::to_string(ret)); + } + path = wt.we_wordv[0U]; + wordfree(&wt); +#else // !defined(HAS_WORDEXP_H) + utils::string::replace(path, "~", "%USERPROFILE%"); - return repertory::utils::string::replace(path, "~", home); -} + std::string dest; + dest.resize(::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0)); + ::ExpandEnvironmentStringsA(path.c_str(), dest.data(), + static_cast(dest.size())); + path = dest.c_str(); -[[nodiscard]] auto resolve(std::wstring_view path) -> std::wstring { - return repertory::utils::string::from_utf8( - resolve(repertory::utils::string::to_utf8(path))); +#endif // defined(HAS_WORDEXP_H) + + return path; } #endif // !defined(_WIN32) - } // namespace namespace repertory::utils::path {