From cde0e92591ce74acb059bb12a8f3a464c877f99c Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 2 Aug 2024 22:58:05 -0500 Subject: [PATCH] updated build system --- support/3rd_party/src/utils/path.cpp | 38 +++++----------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/support/3rd_party/src/utils/path.cpp b/support/3rd_party/src/utils/path.cpp index 08cd1c60..9c75fbbf 100644 --- a/support/3rd_party/src/utils/path.cpp +++ b/support/3rd_party/src/utils/path.cpp @@ -36,39 +36,15 @@ static const std::wstring directory_seperator_str_w{ }; [[nodiscard]] auto resolve(std::string path) -> std::string { - static constexpr const std::string_view function_name{ - static_cast(__FUNCTION__), - }; - -#if defined(HAS_WORDEXP_H) - try { - if (not path.empty()) { - 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); - } - - path = wt.we_wordv[0U]; - wordfree(&wt); + 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}); } - } catch (const std::exception &e) { - repertory::utils::error::handle_exception(function_name, e); - } catch (...) { - repertory::utils::error::handle_exception(function_name); - } -#else // !defined(HAS_WORDEXP_H) - repertory::utils::string::replace(path, "~", "%USERPROFILE%"); + }); - 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(); -#endif // defined(HAS_WORDEXP_H) - - return path; + return repertory::utils::string::replace(path, "~", home); } } // namespace