updated build system
This commit is contained in:
parent
85b28f7ee3
commit
cde0e92591
38
support/3rd_party/src/utils/path.cpp
vendored
38
support/3rd_party/src/utils/path.cpp
vendored
@ -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<const char *>(__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<DWORD>(dest.size()));
|
||||
path = dest.c_str();
|
||||
#endif // defined(HAS_WORDEXP_H)
|
||||
|
||||
return path;
|
||||
return repertory::utils::string::replace(path, "~", home);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user